Trivial performance questions
Terry Reedy
tjreedy at udel.edu
Sat Oct 18 15:25:30 EDT 2003
"Bryan" <belred1 at yahoo.com> wrote in message
news:Klckb.807073$YN5.806740 at sccrnsc01...
> can you explain in more detail why "if x is None:" is better/faster
than "if x == None:"? i guess i don't fully understand "is".
'is' means same object (same identity) For CPython, this is a trivial
comparison of addresses. == means same value, which comparison
starts, I believe, with calling type(x) and type(None) to see if they
are comparable.
> my fingers always seem to want to type "if not x:", but that is
probably worse still since it includes (), [], {}, '', False, None .
It is good or erroneous depending on whether 'not x' is or is not the
appropriate condition ;-)
Terry J. Reedy
More information about the Python-list
mailing list