It's not copying the methods.
When you use instance.method
, it creates a new bound method
object that binds the method to that instance. This is similar to multiple closures of the same function in different environments.
Note that obj1.method
and obj2.method
are not actually the same bound method objects. Since you didn't save either object, the first object was discarded immediately and its address was used for the second one. You can prevent this by assigning them to variables.
method1 = obj1.method
method2 = obj2.method
print(hex(id(method1)))
print(hex(id(method2)))
Since the objects can't be garbage collected, they get different IDs.
For other examples of this, see Unnamed Python objects have the same id