© examsnet.com
Question : 11 of 12
Marks: +1, -0
“Stack is a linear data structure which follows a particular order in which the operations are performed.”
What is the order in which the operations are performed in a Stack ?
Name the List method/function available in Python which is used to remove the last element from a list implemented stack.
Also write an example using Python statements for removing the last element of the list.
[CBSE 2022 Code 91]
Solution:  
Order of operations: A stack follows LIFO (Last In, First Out): the element pushed last is the first one to be popped. Insertion (PUSH) and deletion (POP) both take place at one end only, called the TOP of the stack.
List method: pop() (called without an index, it removes and returns the last element of the list, i.e. the top of the stack).
Example:
stack = [10, 20, 30]      # 30 is at the top
item = stack.pop() # removes the last element
print(item) # 30
print(stack) # [10, 20]
© examsnet.com
Advertisements
Go to Question: