简体   繁体   中英

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

Look to my Python session:

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

but:

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

Why??

PS . Thanks for help! Python have very strange design - do not support chaining:

That is root of my problem...

list.insert returns None ; when you print k you're printing the new state of the list.

You are checking the return type to None in case 1 which would evaluate to True . Python insert returns None

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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