By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,957 Members | 2,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,957 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.