class Stack:
def __init__(self):
self.data = []
def __len__(self):
return len(self.data)
def is_empty(self):
return len(self.data) == 0
def push(self, d):
self.data.append(d)
def gettop(self):
if self.is_empty():
return 'empty'
return self.data[-1]
def pop(self):
if self.is_empty():
return 'empty'
return self.data.pop() # 先进后出
satck = Stack()
satck.push(1)
satck.push(2)
print(satck.data)
print(satck.gettop())
print(satck.pop())
print(satck.data)
06-02
326
04-23
453
06-10
600
10-30
1144