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
Post a Comment