当前位置:网站首页>问题解决:AttributeError: ‘NoneType‘ object has no attribute ‘append‘
问题解决:AttributeError: ‘NoneType‘ object has no attribute ‘append‘
2022-07-05 02:20:00 【公子聪】
python 中的 append() 方法用于在列表末尾添加新的对象。
该方法无返回值(即返回值为空),但是会修改原来的列表。
a = [1, 2, 3]
b = a.append(4)
print(a) # [1, 2, 3, 4]
print(b) # None
从结果执行中可见,append() 没有返回值(b 的值为空),所以如果在 b 上添加新的对象,即:
b.append(5)
执行后就会报错 AttributeError: 'NoneType' object has no attribute 'append'
因为b是一个空类型,不是一个列表类型,所以没有 append() 方法,此处应该把 b.append(5) 修改为 a.append(5)
小结:
append() 方法用于在列表末尾添加新的对象,没有返回值,但是会修改原来的列表。
所以,在使用 append() 方法时,不能将其执行结果赋值给其他变量后再查看或其他操作。
参考资料:
https://www.runoob.com/python/att-list-append.html
https://blog.csdn.net/weixin_44249185/article/details/102580621
边栏推荐
- Kotlin - 协程 Coroutine
- Collection of gmat750 wrong questions
- RichView TRVUnits 图像显示单位
- 使用druid連接MySQL數據庫報類型錯誤
- Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
- Pytorch common code snippet collection
- Advanced learning of MySQL -- Application -- Introduction
- 如何搭建一支搞垮公司的技术团队?
- 使用druid连接MySQL数据库报类型错误
- Security level
猜你喜欢
openresty ngx_lua執行階段
Lsblk command - check the disk of the system. I don't often use this command, but it's still very easy to use. Onion duck, like, collect, pay attention, wait for your arrival!
One plus six brushes into Kali nethunter
[download white paper] does your customer relationship management (CRM) really "manage" customers?
[uc/os-iii] chapter 1.2.3.4 understanding RTOS
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
如何搭建一支搞垮公司的技術團隊?
Official announcement! The third cloud native programming challenge is officially launched!
Matrixone 0.2.0 is released, and the fastest SQL computing engine is coming
R语言用logistic逻辑回归和AFRIMA、ARIMA时间序列模型预测世界人口
随机推荐
[technology development-26]: data security of new information and communication networks
Win: use shadow mode to view the Desktop Session of a remote user
Practice of tdengine in TCL air conditioning energy management platform
Using druid to connect to MySQL database reports the wrong type
STL container
Exploration of short text analysis in the field of medical and health (II)
One plus six brushes into Kali nethunter
Leetcode takes out the least number of magic beans
官宣!第三届云原生编程挑战赛正式启动!
JVM - when multiple threads initialize the same class, only one thread is allowed to initialize
Limited query of common SQL operations
Outlook:总是提示输入用户密码
Erreur de type de datagramme MySQL en utilisant Druid
Can you really learn 3DMAX modeling by self-study?
Marubeni Baidu applet detailed configuration tutorial, approved.
. Net starts again happy 20th birthday
【附源码】基于知识图谱的智能推荐系统-Sylvie小兔
Introduce reflow & repaint, and how to optimize it?
Summary and practice of knowledge map construction technology
Official announcement! The third cloud native programming challenge is officially launched!