append()函数使用报错解决:AttributeError: 'NoneType' object has no attribute 'append'
问题描述Python代码中使用append()函数后报错:AttributeError: ‘NoneType’ object has no attribute ‘append’代码:L = L.append('a')解决方法将“L = L.append(‘a’)”改为L.append(‘a’)后问题解决原因解释append会修改L本身,并且返回None。不能把返回值再赋值给La...
文章共205字 · 阅读需要大约1分钟
一键AI生成摘要,助你高效阅读
问答
·
问题描述
Python代码中使用append()函数后报错:
AttributeError: ‘NoneType’ object has no attribute ‘append’
代码:
L = L.append('a')
解决方法
将“L = L.append(‘a’)”改为L.append(‘a’)后问题解决
原因解释
append会修改L本身,并且返回None。不能把返回值再赋值给L
append()函数用法介绍
作用:在列表末尾添加新的对象
语法:list.append(obj)
参数:obj:添加至列表末尾的对象
返回值:该方法无返回值,会修改原来的列表
例子:
L = ['A','B','C']
L.append('D')
print L
输出:[‘A’, ‘B’, ‘C’, ‘D’]
更多推荐
已为社区贡献1条内容
所有评论(0)