In Python, how does a for loop with `range` work?

前端 未结 6 1248
醉梦人生
醉梦人生 2021-01-03 19:20
for number in range(1,101): 
    print number

Can someone please explain to me why the above code prints 1-100? I understand that the range functio

6条回答
  •  孤城傲影
    2021-01-03 19:44

    number is a variable in which each value in the range is placed.

    range actually returns an iterator, and the for is responsible for advancing it through the range.

提交回复
热议问题