list--pop()
发现一个神奇的问题:
>>> list = range(101)
>>> type(list)
<class 'range'>
>>> list = [1,2,3] >>> type(list) <class 'list'> >>> list [1, 2, 3] >>> list.pop(a) 2 >>> list.pop(a) 3 >>> list.pop(a) Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: pop index out of range >>> list.pop(0) 1 >>> list [] >>> list.pop(0) Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: pop from empty list >>>
1.range()生成的不是list类型,而是range类型
2.pop()应该是弹出对应下标的元素啊?怎么pop(a)像是等价于pop(1)呢?