append导致TypeError: 'NoneType' object is not iterable

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

因为:

描述

append() 方法用于在列表末尾添加新的对象。

语法

append()方法语法:

list.append(obj)

参数

  • obj -- 添加到列表末尾的对象。

返回值

该方法无返回值,但是会修改原来的列表。

------------------------

当一个函数没有return语句,函数会返回None,此时如果将函数返回值赋给多个变量,则容易出现上述错误。

猜你喜欢

转载自www.cnblogs.com/qiu-1010/p/10622527.html