class Numbers:
data = []
def read_from_row(self, row):
row_list = list(row)
for i in row_list:
self.data.append(i)
list1 = ["15","16"]
list2 = ["17","18"]
instance = Numbers()
instance.read_from_row(list1)
print(instance.data)
instance = Numbers()
instance.read_from_row(list2)
print(instance.data)
Here is the piece of code. So in the beginning instance is the instance of the class Numbers and after reading the first list print(instance.data) naturally prints ['15', '16']. But then I create new instance of class Numbers again still in the same variable instance, but after reading from the second list it still contains data from the first list for some reason. Outputting ['15', '16', '17', '18'].
I'm sorry, I'm a beginner at python and after coding C/C++ for so long I can't understand why does this happen or what's expected behavior. I'm using Python 2.7.
Thanks in advance.