Using List as Stack in Python

This Python script will show you how to use List in Python as a Stack

Source code :

stack = ["Apple", "Google", "Twitter"]

stack.append("Facebook") #Pushing Facebook to the Stack

print(stack)

popped = stack.pop()
print("Popped from stack : " , popped)

print(stack)

Output :

['Apple', 'Google', 'Twitter', 'Facebook']
Popped from stack :  Facebook
['Apple', 'Google', 'Twitter']

Output :


                

Comments :