list [0:9]和list [0:10]具有相同的值

时间:2017-12-25 10:56:45

标签: python

list[0:9]list[1:10]在我的python IDLE中显示相同。我不确定背后的逻辑,有人可以解释一下。请参阅下面检索的值。

>>> list[0:9]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list[0:10]
[1, 2, 3, 4, 5, 6, 7, 8, 9]

enter image description here

1 个答案:

答案 0 :(得分:1)

在后者中,第二个索引超过了最后一个元素。

l = [1,2,3]
l[0:100]
=> [1,2,3]
相关问题