469,364 Members | 2,398 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,364 developers. It's quick & easy.

Is the Python for statement the same as for each in other languages?

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?
Apr 8 '08 #1
2 960
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):
...
Diez
Apr 8 '08 #2
On 8 avr, 19:55, "Diez B. Roggisch" <de...@nospam.web.dewrote:
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
Apr 8 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

220 posts views Thread by Brandon J. Van Every | last post: by
699 posts views Thread by mike420 | last post: by
226 posts views Thread by Stephen C. Waterbury | last post: by
14 posts views Thread by David MacQuigg | last post: by
28 posts views Thread by Maboroshi | last post: by
68 posts views Thread by Lad | last post: by
112 posts views Thread by mystilleef | last post: by
852 posts views Thread by Mark Tarver | last post: by
26 posts views Thread by Frank Samuelson | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.