首页 > 其他分享 >AttributeError: 'NoneType' object has no attribute 'append'

AttributeError: 'NoneType' object has no attribute 'append'

时间:2023-01-09 07:11:23浏览次数:42  
标签:no attribute object append AttributeError NoneType

在写python脚本时遇到AttributeError: 'NoneType' object has no attribute 'append'

a=[]
b=[1,2,3,4]
a = a.append(b)

执行一次后发现a的类型变为了NoneType。
下次执行时就会出现如题所示的错误。

把'a = a.append(b)'改为'a.append(b)'后问题解决。

原因:append会修改a本身,并且返回None。不能把返回值再赋值给a。

标签:no,attribute,object,append,AttributeError,NoneType
From: https://www.cnblogs.com/xinkevinzhang/p/17035944.html

相关文章