consider the following class
import random
class MyClass():
arr = []
def __init__(self, size):
for index in range(size):
self.arr.append(random.random())
print("the size of the array is : " + str(len(self.arr)))
MyClass(4)
MyClass(3)
MyClass(2)
MyClass(1)
The output while running the following code is:
the size of the array is : 4
the size of the array is : 7
the size of the array is : 9
the size of the array is : 10
It's clearly that every time the constructor gets called, the context is not getting maintained
instead the array values all seems to get appended into a gloabal variable called arr
I want to know why are the object variables not maintaining the context and leaking into each other?