Python - Why does extend() and append() return None (void)? [duplicate]

给你一囗甜甜゛ 提交于 2020-03-16 02:38:06

问题


Possible Duplicate:
why does python's list.append evaluate to false?

In my opinion, I think list1.extend(list2) and list1.append(num) should return the mutated list rather than None (void). As well as having the side effect of destructively mutating the original list.


回答1:


I believe the intent was to promote readable code and reduce bugs. This decision was made a very long time ago, but you can probably find more by looking at the archives of the python/python-dev mailing lists.

Python3 would have been the opportunity to change this behaviour, but as you see it remains, so is not considered a design mistake by the development team



来源:https://stackoverflow.com/questions/10678226/python-why-does-extend-and-append-return-none-void

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!