Tuple assignment and generators?

Carl Banks invalidemail at aerojockey.com
Fri May 5 13:16:27 EDT 2006


vdrab wrote:
> I guess the take-away lesson is to steer clear from any reliance on
> object identity checks, if at all possible.

BINGO!


>  Are there any other such
> "optimizations" one should like to know about?

You don't have to know about them, as long as you use the operators
correctly.

== tests equality.  is tests identity.  Use is ONLY when you are
testing whether two things are the same object.  Otherwise, use ==.
When deciding which operator to use, ask yourself this: would the
result still be true if they were different objects with the same
value?  If yes, then use ==.  0 == 0 should be true even if the two
zeros are different objects.

Corrollary:

You should test for singleton objects with is.  None, NotImplemented,
and Ellipsis are singleton objects; this is part of the language and
not an implementation detail.  You can rely on it.


Carl Banks




More information about the Python-list mailing list