comparison with None
aleax at mac.com
Sat Apr 21 04:48:02 CEST 2007
Gabriel Genellina <gagsl-py2 at yahoo.com.ar> wrote:
> En Fri, 20 Apr 2007 11:40:00 -0300, Alex Martelli <aleax at mac.com> escribió:
> > I'm still interested to know where that erroneous quote from Alan Isaac
> > comes from, because if it's in Python's docs, it can be fixed.
> It was a partial quote, that's why it appeared to be wrong:
> Library reference, 3.3 Comparisons
> "Objects of different types, except different numeric types and different
> string types, never compare equal; such objects are ordered consistently
> but arbitrarily."
> Reference Manual, 5.9 Comparisons
> "The objects need not have the same type. If both are numbers, they are
> converted to a common type. Otherwise, objects of different types always
> compare unequal, and are ordered consistently but arbitrarily."
> (Apart from the latter not menctioning string types too, looks good to me).
Right. However, it might be worth underscoring that this applies to
_built-in_ types, and user-defined types are free to implement different
comparison semantics, although that should be done with care and good
taste; for example, one might have a collection type defining __eq__ to
mean "the same set of items as the other [iterable] operand in any
order", though that might cause weird behavior such as a==b but b!=a
(unfortunately there's no __req__, and __coerce__ is not involved in
Still, not a major concern -- numbers and strings _do_ exhaust a vast
majority of the use cases for object of different types comparing equal.
More information about the Python-list