python 实现一个简单的栈
代码如下:
class Stack(object):
def __init__(self):
self.value = []
def push(self,x):
self.value.append(x)
def pop(self):
self.value.pop()
stack = Stack()
stack.push(0)
stack.push(1)
stack.push(2)
stack.push(3)
print(stack.value)
stack.pop()
print(stack.value)
stack.pop()
stack.pop()
stack.pop()
print(stack.value)
输出如下:
/usr/bin/python3 /home/zh/workSpace/python/Test1/venv/StackTest.js.py
[0, 1, 2, 3]
[0, 1, 2]
[]
Process finished with exit code 0