当前位置:网站首页>问题解决: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
边栏推荐
- PowerShell: use PowerShell behind the proxy server
- Advanced conditional statements of common SQL operations
- Huawei machine test question: longest continuous subsequence
- Yolov5 model training and detection
- RichView TRVUnits 图像显示单位
- Start the remedial work. Print the contents of the array using the pointer
- openresty ngx_ Lua execution phase
- Valentine's Day flirting with girls to force a small way, one can learn
- Video display and hiding of imitation tudou.com
- Binary tree traversal - middle order traversal (golang)
猜你喜欢

Three properties that a good homomorphic encryption should satisfy

Visual studio 2019 set transparent background (fool teaching)

Runc hang causes the kubernetes node notready

Learn game model 3D characters, come out to find a job?

Introduce reflow & repaint, and how to optimize it?

Interesting practice of robot programming 14 robot 3D simulation (gazebo+turtlebot3)

Variables in postman

Introduce reflow & repaint, and how to optimize it?

Restful Fast Request 2022.2.1发布,支持cURL导入

Matrixone 0.2.0 is released, and the fastest SQL computing engine is coming
随机推荐
Do you know the eight signs of a team becoming agile?
Which common ports should the server open
Richview trvunits image display units
如何搭建一支搞垮公司的技术团队?
MATLB | multi micro grid and distributed energy trading
Yolov5 model training and detection
Codeforces Round #770 (Div. 2) ABC
Data guard -- theoretical explanation (III)
CAM Pytorch
RichView TRVStyle MainRVStyle
Interesting practice of robot programming 15- autoavoidobstacles
One plus six brushes into Kali nethunter
Process scheduling and termination
Some query constructors in laravel (2)
R language uses logistic regression and afrima, ARIMA time series models to predict world population
Erreur de type de datagramme MySQL en utilisant Druid
Win:使用 Shadow Mode 查看远程用户的桌面会话
Win: enable and disable USB drives using group policy
Valentine's Day flirting with girls to force a small way, one can learn
Security level