简体   繁体   English

这个表达式在Python中是正确的:{} .keys()。insert(0,“”)== None。 为什么?

[英]This expression is true in Python: {}.keys().insert(0, “”) == None. Why?

Look to my Python session: 看看我的Python会话:

>>> {}.keys().insert(0, "") == None
True

but: 但:

>>> k = {}.keys()
>>> k
[]
>>> k.insert(0, "")
>>> k
['']

Why?? 为什么??

PS . PS Thanks for help! 感谢帮助! Python have very strange design - do not support chaining: Python有非常奇怪的设计 - 不支持链接:

That is root of my problem... 这是我问题的根源......

list.insert returns None ; list.insert 返回 None ; when you print k you're printing the new state of the list. 当你打印k你正在打印列表的新状态。

You are checking the return type to None in case 1 which would evaluate to True . 您正在检查案例1中的返回类型为None ,这将评估为True Python insert returns None Python insert返回None

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM