为什么 [1].append(2) 计算结果为 None 而不是 [1,2]? [英] Why does [1].append(2) evaluate to None instead of [1,2]?
本文介绍了为什么 [1].append(2) 计算结果为 None 而不是 [1,2]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么 print [1].append(2)
计算结果为 None?我期望 [1,2]
解决方案
那是因为 append 什么都不返回 (= None
).
Why does print [1].append(2)
evaluate to None? I expect [1,2]
>>> print [1].append(2)
None
解决方案
That's because append returns nothing (= None
).
>>> print [1].append(2)
None
这篇关于为什么 [1].append(2) 计算结果为 None 而不是 [1,2]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文