PEP 276 -- What else could iter(5) mean?

Remco Gerlich scarblac at pino.selwerd.nl
Sun Mar 3 07:50:24 EST 2002


Cromwell, Jeremy <jcromwell at ciena.com> wrote in comp.lang.python:
> If python was to allow "for i in 5:", is there any other meaning that would
> be appropriate besides the one detailed in PEP 276?

Yes.

It should give an error - 5 is not a sequence, so 'i in 5' is nonsense.

If you really want to change that, making it equivalent to for i in [5]:
seems the most natural meaning to me.

For iterating over the values 0..4, we have the nicely explicit and Pythonic
for i in range(5):. I haven't seen one very good reason why we need a second
way to do that - saving a few characters surely isn't enough.

-- 
Remco Gerlich



More information about the Python-list mailing list