title: Python: How to create unique list-type object on initialization of default function argument?
body: <p>There is a class, which constructor takes an argument of "list type". Default value of this argument is empty list. Constructor uses this argument to initialize one of class data members.
  Then, when I create two different instance objects of this class, both of them points to te same list. Why is that?</p>
  
  <p>I've tried to set default value to None, and then conditionally create new empty list in the class constructor body. And this works. Different object instances have different list in their class data members.
  But I would like to know why it doesn't work as I would expect, when I create a list in function argument default value init, like in the code below:</p>
  
  <pre><code>class myClass:
      def __init__(self, user_list=list()):
          self.__class_list = user_list
  
      def addSomethingToList(self, a, b):
          self.__class_list.append([a,b])
  
      def whoAmI(self):
          return hex(id(self.__class_list))
  
      def getList(self):
          return self.__class_list
  
  A = myClass()
  B = myClass()
  
  A.addSomethingToList(1,2)
  B.addSomethingToList(33,44)
  
  print("A",A.whoAmI(), A.getList())
  print("B",B.whoAmI(), B.getList())
  
  ##################
  #Expected results:
  A 0x7f6dd49a6108 [[1, 2]]
  B 0x7f6dd49a6148 [[33, 44]]
  
  #Actual results:
  A 0x7f736f1f40c8 [[1, 2], [33, 44]]
  B 0x7f736f1f40c8 [[1, 2], [33, 44]]
  </code></pre>