Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

stacks in python

# Python program to
# demonstrate stack implementation
# using list
  
stack = []
  
# append() function to push
# element in the stack
stack.append('a')
stack.append('b')
stack.append('c')
  
print('Initial stack')
print(stack)
  
# pop() function to pop
# element from stack in
# LIFO order
print('
Elements popped from stack:')
print(stack.pop())
print(stack.pop())
print(stack.pop())
  
print('
Stack after elements are popped:')
print(stack)
  
# uncommenting print(stack.pop())
# will cause an IndexError
# as the stack is now empty
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #stacks #python
ADD COMMENT
Topic
Name
8+5 =