python - Difference between not dict and not dict=={} -


came in today , debugged find there deviation in behaviour predicted result of not adict being treated differently not adict=={}. in know highlight differences between these 2 forms please.

deviation caused on following line of code

if not adicta , not adictb: 

both equal {} , yet if condition didn't return true.

line of code changed to

if not adicta=={} , not adictb=={}: 

and code worked expected.

you right in thinking empty dictionaries false in boolean context. therefore, not {} , empty_dict == {} equivalent, however...

in first one, checking if false.

>>> not {} true 

but in second one, checking if empty (therefore false) , reversing not.

>>> not not {}  # doing. false 

you different results because not testing same condition.


Comments

Popular posts from this blog

javascript - How to name a jQuery function to make a browser's back button work? -

collision detection - C++ library for mesh to mesh intersection: what is available? -

python - Django-easy-pdf: xhtml2pdf reporting reportlab 2.2+ is required, but 3.0 installed -