Group_Coder

Using lists (built-in stack methods)

Jul 24th, 2023
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. # Initialize an empty list to represent the stack
  2. stack = []
  3.  
  4. # Push elements onto the stack
  5. stack.append(1)
  6. stack.append(2)
  7. stack.append(3)
  8.  
  9. # Print the current state of the stack
  10. print("Stack after pushing elements:", stack)
  11.  
  12. # Pop elements from the stack
  13. popped_element = stack.pop()
  14. print("Popped element:", popped_element)
  15.  
  16. # Print the current state of the stack after popping
  17. print("Stack after popping:", stack)
  18.  
Advertisement
Add Comment
Please, Sign In to add comment