0

I have the following code:

class test:
    def __init__(self, a=[None,None], b=[None,None], c=[None,None]):
        self.a = a
        self.b = b
        self.c = c

new = [test(), test()]
new[0].a[0] = 15
new[1].a

I cannot understand why the second entry changes as well. How did it turn out that both elements of the list "new" are the same object?

EDIT: For the solution, try this link" What is the pythonic way to avoid default parameters that are empty lists?

Cindy Almighty
  • 903
  • 8
  • 20

0 Answers0