Object list is global if append, but not if list=value
I've created a class, that takes in a list, and uses it for math functions. Anyways, I noticed a weird quirk with the system: if I append the list of element x, all objects in the class have access to it, but if I set the list=x, than the list is local. X is also a list.
class Wrong:
list=[]
def __init__(self, foo):
for i in foo:
self.list.append(i)
class Right:
list=[]
def __init__(self, foo):
self.list=foo
list=[1,2,3]
wrong1 = Wrong(list)
wrong2 = Wrong(list)
right1 = Right(list)
right2 = Right(list)
print(wrong1.list)
print(wrong2.list)
print(right1.list)
print(right2.list)
I expect the outputs to be the same, but when printed, it's
[1, 2, 3, 1, 2, 3]
[1, 2, 3, 1, 2, 3]
[1, 2, 3]
[1, 2, 3]
I'm using python 3.7.2, in case that changes anything.