【发布时间】:2012-08-24 07:29:18
【问题描述】:
N=8
f,g=4,7
indexList = range(N)
print indexList
print f, g
indexList.pop(f)
indexList.pop(g)
在此代码中,我收到一条错误消息,指出 indexList 中的 g 的弹出索引超出范围。
这是输出:
[0, 1, 2, 3, 4, 5, 6, 7]
4 7
Traceback (most recent call last):
indexList.pop(g)
IndexError: pop index out of range
我不明白,g 的值为 7,列表包含 7 个值,为什么无法返回列表中的 7?
【问题讨论】:
标签: python list indexing range