Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下python代码:
a = [0,1,2,3,4,5] del(a[2:7])
这不应该给出“IndexError”吗?如果没有,那为什么?
这会将列表切片从 2 删除到 7 之前。列表切片不会引发索引错误,如果它们超出列表的末尾,它们会返回列表的整个剩余部分。
>>> a = list(range(10)) >>> a [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> a [5:20] [5, 6, 7, 8, 9]