title: implementing immutable stack in python
body: <p>Have a question about creating new objects using existing objects in python. Example: I want to implement immutable Stack using python. However, catch here is, whenever I am creating new object, it should be created from existing object:
  in below example, how can I update push function to create a copy of <code>s1</code> from <code>s0</code> and append value <code>2</code> to <code>S1</code>?</p>
  <pre><code>class Stack:
      def __init__(self):
          self.items = []
      def push(self, item):
          self.items.append(item)
      def pop(self):
          return self.items.pop()
      def peek(self):
          return self.items[-1]
      def __str__(self):
          return str(self.items)
  
  if __name__ == &quot;__main__&quot;:
      s0 = Stack()
      s1 = s0.push(2)
      s2 = s1.push(3)
  </code></pre>