Using Lists as Stacks : List Pop « List « Python






Using Lists as Stacks

Using Lists as Stacks


#To add an item to the top of the stack, use append(). To retrieve an item from 
#the top of the stack, use pop() without an explicit index.

stack = [3, 4, 5]
stack.append(6)
stack.append(7)
print stack

stack.pop()

print stack

print stack.pop()

print stack.pop()

print stack


           
       








Related examples in the same category

1.Deleting List ElementsDeleting List Elements
2.List pop([i])List pop([i])