我正在一台安装有Python版本3.2.3的Linux机器上工作。
每当我尝试使用
list.clear()
时,会出现异常。>>> l = [1, 2, 3, 4, 5, 6, 7]
>>> l.clear()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'clear'
我在我的Mac上使用Python 3.4.3时,同样的代码可以顺利运行。这是由于Python版本之间的差异还是我遗漏了什么?
del l[:]
来代替。 - dav1d