Why does range(start, end) not include end?

后端 未结 9 1389
夕颜
夕颜 2020-11-22 10:24
>>> range(1,11)

gives you

[1,2,3,4,5,6,7,8,9,10]

Why not 1-11?

Did they just decide to do it lik

9条回答
  •  再見小時候
    2020-11-22 11:17

    Consider the code

    for i in range(10):
        print "You'll see this 10 times", i
    

    The idea is that you get a list of length y-x, which you can (as you see above) iterate over.

    Read up on the python docs for range - they consider for-loop iteration the primary usecase.

提交回复
热议问题