[Tutor] The Whole Tree
Dave Angel
davea at davea.name
Mon Jun 17 01:36:34 CEST 2013
On 06/16/2013 01:21 PM, Jim Mooney wrote:
> My first impression of Python was that it had dynamic types but didn't
> mix them. so if I was wrong on equality, is there a general rule of
> what different types can still be equal? Is it an inheritance thing?
>
Several other good replies, but I'll give my two cents as well.
Python types are either really dynamic, or non-existent, depending on
how you define them. In particular names have no types at all, unless
you want to count the type of the object the name is currently connected
to. And if that's what you mean, then names are extremely dynamic,
because a name which was bound to a str a minute ago may be currently
bound to a file, and may be soon bound to an iterator.
As for whether objects of different types can be equal. The answer is
yes, if one or both of them define the special methods __eq__() and
__ne__(). If neither of those exist, the objects are unequal.
But you may be asking instead which standard library types have those
special methods, and how do they behave. In that case, I defer to
Steven's answer.
--
DaveA
More information about the Tutor
mailing list