.
>>> range(2, 19)
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
python 3.
>>> range(2..., 19)
range(2, 19)
而这样
>>> list(range(2, 19))
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17...这是因为,在py2中range()是作为内置函数, 而在py3中是作为一个内置的方法
注意看以下的源代码(部分):
py2
def range(start=None, stop=None, step...For example, range(4) returns [0, 1, 2, 3]. The end point is omitted!
...range(4) produces 0, 1, 2, 3.
These are exactly the valid indices for a list of 4 elements.