Another snippet shows that instance variables can be created during any moment of an object's life. Moreover, it lists the contents of each object, using the built-in __dict__
property that is present for every Python object.
class Demo:
def __init__(self, value):
self.instance_var = value
d1 = Demo(100)
d2 = Demo(200)
d1.another_var = 'another variable in the object'
print('contents of d1:', d1.__dict__)
print('contents of d2:', d2.__dict__)
This example shows that modifying the instance variable of any object has no impact on all the remaining objects. Instance variables are completely isolated from each other.
contents of d1: {'instance_var': 100, 'another_var': 'another variable in the object'}
contents of d2: {'instance_var': 200}
output