[AppleScript] 纯文本查看 复制代码
class Stack(object): """栈""" def __init__(self): self.items = []
def is_empty(self): """判断是否为空""" return self.items == []
def push(self, item): """加⼊元素""" self.items.append(item)
def pop(self): """弹出元素""" return self.items.pop()
def peek(self): """返回栈顶元素""" return self.items[len(self.items)-1]
def size(self): """返回栈的⼤⼩""" return len(self.items)
if __name__ == "__main__": stack = Stack() stack.push("hello") stack.push("world") stack.push("itcast") print stack.size() print stack.peek() print stack.pop() print stack.pop() print stack.pop()