![]() ![]() |
| |||||||||
| Hotspots: Slides and Code TA Corner Comments? Announcements FAQ Static Webspace | ||||||||||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
| Ok. So Value starts out at 0. What happens to the value of value after each time through the for loop? -Albert d'Heurle |
Its just a more fancy way of writing a 'for' loop. list1 = range(1,5)The above line means that list1 = [1, 2, 3, 4]Now the 'for' loop just goes through every value in the list. In short, its the same thing as writing for x in range(1,5):- Bobby Mathew |
| That's just the way that range is defined. It goes from the first value up to but not including the second value, so range(1,5) excludes 5 from the list. There is an obscure justification that makes this useful in some situations, but mostly it's a pain that causes programming errors until you get used to it. Every programming language contains gotchas like this. Python has fewer than most. Colin Potts |