1 · Learn and explore
Study this example, identify inputs and outputs, then trace the key variables. Run and adapt it in Python 3.
class Stack:
def __init__(self): self.items = []
def push(self, value): self.items.append(value)
def pop(self):
if not self.items: raise IndexError("stack underflow")
return self.items.pop()
def peek(self):
if not self.items: raise IndexError("stack empty")
return self.items[-1]
s = Stack()
s.push('A'); s.push('B')
