【发布时间】:2020-01-04 14:59:40
【问题描述】:
我在 python 3.7.1 上。
我正在使用数据结构,当使用列表时,我遇到了一个错误。 当我尝试访问索引 -1 时,python 给了我列表中的最后一个条目。
我打开了 python shell,并运行了以下命令:
>>> l = [0,1,2]
>>> l[-1]
2
>>> l[3]
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
l[3]
IndexError: list index out of range
这可能是由于 python 3.7.1 上的一个错误,但是除了更新 python 之外还有其他方法可以解决这个问题吗?我正在进行一个项目。
【问题讨论】:
-
python索引从0开始
-
我不知道您认为实际会发生什么?
标签: python python-3.7