0% found this document useful (0 votes)
4 views1 page

Python Stack Operations Explained

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Python Stack Operations Explained

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Stack

Aim: To create a stack and use functions related to stack


Requirement: Python IDE
Code:
stack = [ ]
[Link](1)
[Link](2)
[Link](3)
[Link](4)
[Link](5)
print(stack)
print([Link]())
print([Link]())
print([Link]())
def size(a):
return len(a)
def empty(a):
if len(a)==0:
print("The stack is empty")
else:
print("The stack is not empty")
empty(stack)
print(size(stack))
Output:

Results: Push and Pop function was used to add and remove elements in stacks. Len and isEmpty
functions were defined to find out size and to check whether the stack is empty or not.

You might also like