如何在 python 中删除堆栈中的所有项目

How to remove all the items inside the stack in python

堆栈=['Hatdog','Hamburger']

stack.empty()

打印(堆叠)

如果您使用列表实现堆栈,您应该遍历列表,直到它为空,例如:

stack=['Hatdog','Hamburger']

while (not stack == []):
    stack.pop()

print (stack)

在 Python 中的堆栈实现上检查此 link:https://www.geeksforgeeks.org/stack-in-python/