'==' vs. 'is' behavior

François Pinard pinard at iro.umontreal.ca
Mon Nov 29 17:11:51 EST 1999


duncan at rcp.co.uk (Duncan Booth) writes:

> >>> print a is b

By the way, is there common wisdom (or rather, maybe, usage-standards-to-be)
about using `is' instead of `=='?

In most cases I have seen so far, it is unusual that one really has to
resort to `is', because `==' usually does something proper on average.
But even then, I prefer writing `is None' than `== None', because it is
more exact.  I could of course use the tested things as mere logical values,
as a way to escape that tiny problem (:-), but sometimes it is just clearer
to write things explicitly.

So, I was just wondering if someone would not have a clear set of good
habits on that matter.  (I feel just a bit like "Mégère", who indirectly
induced the Trojan war by offering the golden apple to three goddesses :-).

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list