>> {} .keys (). insert (...">

This expression is true in Python: {} .keys (). Insert (0, "") == None. What for?

Take a look at my Python session:

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

and

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

Why??

PS . Thanks for the help! Python has a very strange design - it doesn't support chaining:

This is the root of my problem ...

+3


source to share


2 answers


list.insert

returns None

; when k

you print, you print the new state of the list.



+10


source


You are checking the return type for None

case 1, which will evaluate to True

. Python insert

returnsNone



+2


source







All Articles