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

后端 未结 9 1322
夕颜
夕颜 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:01

    Exclusive ranges do have some benefits:

    For one thing each item in range(0,n) is a valid index for lists of length n.

    Also range(0,n) has a length of n, not n+1 which an inclusive range would.

提交回复
热议问题