Can someone point out to me what I'm doing wrong or where my understanding is wrong?
To me, it seems like the code below which instantiates two objects should have separate data for each instantiation.
class Node:
def __init__(self, data = []):
self.data = data
def main():
a = Node()
a.data.append('a-data') #only append data to the a instance
b = Node() #shouldn't this be empty?
#a data is as expected
print('number of items in a:', len(a.data))
for item in a.data:
print(item)
#b data includes the data from a
print('number of items in b:', len(b.data))
for item in b.data:
print(item)
if __name__ == '__main__':
main()
However, the second object is created with the data from the first:
>>>
number of items in a: 1
a-data
number of items in b: 1
a-data