list and adds a method that returns the object.
class Stack(list):
def push(self, x):
self.append(x)
return self
s = Stack().push(1).push(2)
print(s, len(s), isinstance(s, list), s.pop())
What does the program print?Log in to join the discussion.
Loading…