当前位置:网站首页>问题解决: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
边栏推荐
- Yyds dry inventory swagger positioning problem ⽅ formula
- The application and Optimization Practice of redis in vivo push platform is transferred to the end of metadata by
- Uniapp navigateto jump failure
- PowerShell:在代理服务器后面使用 PowerShell
- [机缘参悟-38]:鬼谷子-第五飞箝篇 - 警示之一:有一种杀称为“捧杀”
- Advanced learning of MySQL -- Application -- Introduction
- The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
- He was laid off.. 39 year old Ali P9, saved 150million
- ICSI 311 Parser
- Exploration of short text analysis in the field of medical and health (I)
猜你喜欢
Mysql database | build master-slave instances of mysql-8.0 or above based on docker
Openresty ngx Lua Execution stage
Application and Optimization Practice of redis in vivo push platform
Yyds dry inventory swagger positioning problem ⽅ formula
Go RPC call
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
Exploration of short text analysis in the field of medical and health (I)
A label colorful navigation bar
Restful fast request 2022.2.1 release, support curl import
Yolov5 model training and detection
随机推荐
He was laid off.. 39 year old Ali P9, saved 150million
Vulnstack3
openresty ngx_lua变量操作
Unified blog writing environment
[Digital IC hand tearing code] Verilog edge detection circuit (rising edge, falling edge, double edge) | topic | principle | design | simulation
220213c language learning diary
Learn tla+ (XII) -- functions through examples
Android advanced interview question record in 2022
Collection of gmat750 wrong questions
spoon插入更新oracle数据库,插了一部分提示报错Assertion botch: negative time
Interesting practice of robot programming 14 robot 3D simulation (gazebo+turtlebot3)
Practical case of SQL optimization: speed up your database
Subject 3 how to turn on the high beam diagram? Is the high beam of section 3 up or down
[understanding of opportunity -38]: Guiguzi - Chapter 5 flying clamp - warning one: there is a kind of killing called "killing"
Uniapp navigateto jump failure
Process scheduling and termination
STL container
Some query constructors in laravel (2)
Redis' hyperloglog as a powerful tool for active user statistics
丸子百度小程序详细配置教程,审核通过。