Python3 AttributeError:&x27;列表';对象没有属性';清除';
我正在使用Python版本3.2.3的Linux机器上工作。 每当我尝试执行Python3 AttributeError:&x27;列表';对象没有属性';清除';,python,list,python-3.x,attributeerror,python-3.2,Python,List,Python 3.x,Attributeerror,Python 3.2,我正在使用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 attribu
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'
l=[1,2,3,4,5,6,7]
>>>l.清除()
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
AttributeError:“列表”对象没有属性“清除”
同时,在我的Mac电脑上使用Python3.4.3时,同样的代码运行平稳。
这可能是由于Python版本之间的差异,还是我遗漏了什么
列表。在Python 3.3中添加了clear
引用文件中的章节:
版本3.3中新增了:clear()
和copy()
方法
s.clear()
从s
中删除所有项目(与dels[:]
相同)
有关清除列表的相关讨论和替代方法,请参阅。总之,它与
dell[:]
和l[:]=[]
相同,只是添加了您可以使用dell[:]
来代替。谢谢@谢谢,是的,我就是这么做的。