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

Basic question- for _ in range(#)- What exactly causes the loop?

P: 1
I am really wanting to dissect things so I know why things occur, rather than they just do. The example in my text book says "for i in range", but the same results occur if I use "for x in range" or "for z in range"

Can anyone explain what exactly causes the loop, and what the variable is doing?
Apr 19 '12 #1
Share this Question
Share on Google+
1 Reply

P: 5
range creates a list of numbers actually, so range(10) will be [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

for i in range(10):

causes i to step through that list, at each step i gets it's value from the list.
May 17 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.