栈
class Stack(): def __init__(self): self.__items=[] # 判空 def is_empty(self): return self.__items==[] # 循环遍历 def travel(self): if self.is_empty(): return False for i in self.__items: print(i,end='') print('') # 查看栈顶元素 def peek(self): if self.is_empty(): return False return self.__items[-1] # 栈的长度 def length(self): return len(self.__items) # 添加元素 def add(self,item): self.__items.append(item) # 删除元素 def pop(self): self.__items.pop() if __name__ == '__main__': ss=Stack() for i in range(10): ss.add(i) print(ss.length()) ss.travel() print(ss.peek()) ss.pop() ss.travel()