Is the Python for statement the same as for each in other languages?
bruno.desthuilliers at gmail.com
bruno.desthuilliers at gmail.com
Tue Apr 8 15:53:58 EDT 2008
On 8 avr, 19:55, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> jmDesktop schrieb:
>
> > Thank you. It looks like it is, but I wanted to make sure I
> > understood. Also, I didn't see a "regular" for loop construct either
> > (i=0;i<=10;i++), etc. I'm still new at it, but is there one of those?
>
> Yes, it's foreach. And for your usecase, use
>
> for i in xrange(11):
> ...
Or if you want to both iterate over an iterable and have the 'loop
index', use enumerate:
for index, item in enumerate('this is a test'):
print index, ' : ', item
More information about the Python-list
mailing list