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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ignis
    New Member
    • Apr 2012
    • 1

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

    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?
  • andrean
    New Member
    • May 2012
    • 5

    #2
    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.

    Comment

    Working...