python提示AttributeError: 'NoneType' object has no attribute 'append'【转发】

在写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。
---------------------
作者:冰雪凌萱
来源:CSDN
原文:https://blog.csdn.net/u012910595/article/details/78551129

原文地址:https://www.cnblogs.com/luo30zhao/p/10563116.html