Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python3 AttributeError:&x27;列表';对象没有属性';清除';_Python_List_Python 3.x_Attributeerror_Python 3.2 - Fatal编程技术网

Python3 AttributeError:&x27;列表';对象没有属性';清除';

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

我正在使用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'
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[:]
来代替。谢谢@谢谢,是的,我就是这么做的。