,
script
print Parent.__dict__
print Child1.__dict__
print Child2.__dict__
You will receive a detailed overview of all members of the class and what is stored in them. The output will be
{'__dict__': <attribute '__dict__' of 'Parent' objects>, 'x': 3, '__module__': '__main__', '__weakref__': <attribute '__weakref__' of 'Parent' objects>, '__doc__': None}
{'x': 2, '__module__': '__main__', '__doc__': None}
{'__module__': '__main__', '__doc__': None}
As you can see in child1
'x': 2 was added to the dict. So child1 does not look for the value in it of the parent class, but child2 does
source
share