Answers for "how to represent a stack in python"

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

Code answers related to "how to represent a stack in python"

Python Answers by Framework

Browse Popular Code Answers by Language