I have a pretty basic problem I guess, but I just can't get to the solution. My Code:
class Matrix:
def __init__(self,data):
self.data = data
def __str__(self):
display = []
for row in self.data:
display.append(str(row))
return '\n'.join(display)
a = Matrix([[1, 2], [3, 4]])
print(a.data)
a.data = [[0,0],[0,0]]
print(a.data)
my first print works as intended: [[1,2],[3,4]]
but my second: [[0,0],[0,0]]
How can I stop my attribute value being changed by a.data = [[0,0],[0,0]]
?
So that my second print also yields: [[1,2],[3,4]]
?
I was looking for a solution pretty long, sorry if the question is already asked, I wasn't able to find any solution.