基于列表实现栈

示例

# by luffycity.com

class Stack(object):

    def __init__(self):
        self.data = []

    def push(self,val):
        self.data.append(val)

    def pop(self):
        return self.data.pop()

    def top(self):
        return self.data[-1]   #每次只取最后一个,不删除

_stack = Stack()

_stack.push('佳俊')
_stack.push('咸鱼')

print(_stack.pop())
print(_stack.pop())

'''
    咸鱼
    佳俊
'''

 

posted @ 2020-07-04 09:48  zh_小猿  阅读(109)  评论(0编辑  收藏  举报