Here is my code:
class Foo(object):
def __init__(self, x, y):
self.x = x
self.y = y
def func(self):
self.x[0] -= 1
self.y -= 1
x = [10]
y = 10
a = Foo(x, y)
a.func()
print(x, y)
Output is ([9], 10)
. Why does passing a list to an instance variable and then changing the instance variable also change the original list, but not the original integer?
How do you pass a list to an instance variable in Python, and then change the instance variable without affecting the original list?