为什么append方法在列表中返回None? [英] Why does the append method return None with my list?
本文介绍了为什么append方法在列表中返回None?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以使用"append()"将元素添加到列表中,但是为什么赋值返回None?
I know I can use "append()" to add an element to a list, but why does the assignment return None?
>>> a=[1,2,3]
>>> a.append(4)
>>> print a
[1, 2, 3, 4]
>>> a=a.append(5)
>>> print a
None
>>>
推荐答案
因为您正在将输出分配给没有输出的附加操作,所以代替:
Because you're assigning an output to the act of appending which has no output, so instead of:
a=a.append(5)
您只想要
a.append(5)
这篇关于为什么append方法在列表中返回None?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文