栈
class Stack(): def __init__(self): self.stack = [] def push(self,value): self.stack.append(value) #进栈 def pop(self): if self.stack: self.stack.pop() #出栈 else: raise LookupError('stacke is empty') def is_empty(self): return bool(self.stack) def top(selfs): return selfs.stack[-1] def size(self): return len(self.stack) stack = Stack() stack.push(5) print(stack.top()) stack.push(6) print(stack.size()) stack.pop() stack.pop() print(stack.is_empty())
posted on 2020-04-24 22:56 __director 阅读(88) 评论(0) 编辑 收藏 举报