They are two different instances of the same class. The sayHello
functions are bound methods.
That is, if you have a class instance:
p = Person()
and you lookup an attribute on it:
p.sayHello
then Python first looks at the actual attributes of the instance, and if it does not find the attribute there, it looks at the class. If it finds a class method of that name, it turns it into a bound method, bound to this instance. That is the magic that results in the object instance being passed as the first argument (self
) to sayHello
.
So Person().sayHello is Person().sayHello
creates two instances, creates two different bound methods based on the same method defined on the class, and thus is
returns False
because they're different methods.