Answers for "python3 stack"

1

stack in python

stack = []
# add element in the stack.
stack.append('a')
# delete in LIFO order.
stack.pop()
Posted by: Guest on August-07-2021
0

stack program in python 3

>>> myStack = []

>>> myStack.append('a')
>>> myStack.append('b')
>>> myStack.append('c')

>>> myStack
['a', 'b', 'c']

>>> myStack.pop()
'c'
>>> myStack.pop()
'b'
>>> myStack.pop()
'a'

>>> myStack.pop()
Traceback (most recent call last):
File "<console>", line 1, in <module>
IndexError: pop from empty list
Posted by: Guest on May-25-2020

Python Answers by Framework

Browse Popular Code Answers by Language