I would like to know how Python 3 (not 2, please :P) address the following situation:
I have a class and two instances:
class MyClass:
def something():
pass
a = MyClass()
b = MyClass()
Do a.something
and b.something
share the same memory address, or each one have a something
declared? How the resolution of calling a.something
works?
When I try to see the methods id
, they have the same:
id(a.something), id(b.something) # (4487791304, 4487791304)
But when I use is
to compare if it's the same, the result is `False:
id(a.something) is id(b.something) #
And if I go furthermore, and print the available methods and data attributes of a
or b
, I can see that both of them have the something
declared:
['__class__',
'__delattr__',
'__dict__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__le__',
'__lt__',
'__module__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__',
'__weakref__',
'something']
Thank you.