当前位置:网站首页>问题解决: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
边栏推荐
- Visual explanation of Newton iteration method
- Erreur de type de datagramme MySQL en utilisant Druid
- Kotlin - coroutine
- Marubeni Baidu applet detailed configuration tutorial, approved.
- Yolov5 model training and detection
- openresty ngx_lua变量操作
- Naacl 2021 | contrastive learning sweeping text clustering task
- RichView TRVStyle MainRVStyle
- Interesting practice of robot programming 16 synchronous positioning and map building (SLAM)
- openresty ngx_ Lua variable operation
猜你喜欢
Binary tree traversal - middle order traversal (golang)
The MySQL team development specifications used by various factories are too detailed. It is recommended to collect them!
. Net starts again happy 20th birthday
Application and Optimization Practice of redis in vivo push platform
丸子百度小程序详细配置教程,审核通过。
Icu4c 70 source code download and compilation (win10, vs2022)
Application and Optimization Practice of redis in vivo push platform
R语言用logistic逻辑回归和AFRIMA、ARIMA时间序列模型预测世界人口
openresty ngx_lua執行階段
Subject 3 how to turn on the high beam diagram? Is the high beam of section 3 up or down
随机推荐
【附源码】基于知识图谱的智能推荐系统-Sylvie小兔
. Net starts again happy 20th birthday
官宣!第三届云原生编程挑战赛正式启动!
Asynchronous and promise
Codeforces Global Round 19 ABC
[机缘参悟-38]:鬼谷子-第五飞箝篇 - 警示之一:有一种杀称为“捧杀”
The steering wheel can be turned for one and a half turns. Is there any difference between it and two turns
Win: add general users to the local admins group
[技术发展-26]:新型信息与通信网络的数据安全
使用druid連接MySQL數據庫報類型錯誤
Grpc message sending of vertx
Application and development trend of image recognition technology
spoon插入更新oracle数据库,插了一部分提示报错Assertion botch: negative time
How to make a cool ink screen electronic clock?
Last week's hot review (2.7-2.13)
Pytorch register_ Hook (operate on gradient grad)
Security level
丸子百度小程序详细配置教程,审核通过。
Why do you understand a16z? Those who prefer Web3.0 Privacy Infrastructure: nym
openresty ngx_ Lua execution phase