Why does range(start, end) not include end?
问题 >>> 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 like that at random or does it have some value I am not seeing? 回答1: Because it's more common to call range(0, 10) which returns [0,1,2,3,4,5,6,7,8,9] which contains 10 elements which equals len(range(0, 10)) . Remember that programmers prefer 0-based indexing. Also, consider the following common code snippet: for i in range(len(li)): pass Could you see that if range() went up to exactly len(li) that