Open links in new tab
  1. A stack is a linear data structure that follows the LIFO (Last In, First Out) principle. In Python, stacks can be implemented in multiple ways, but the most common and efficient methods for Class 12 programs are using lists or collections.deque.

    Using Python List

    Lists in Python have built-in methods like append() and pop() which make them suitable for stack operations.

    Steps:

    1. Push Operation – Use append() to add elements.

    2. Pop Operation – Use pop() to remove the last element.

    3. Peek Operation – Access the last element without removing it.

    4. Check Empty – Use len(stack) == 0.

    # Stack implementation using list
    stack = []

    # Push elements
    stack.append('A')
    stack.append('B')
    stack.append('C')
    print("Initial Stack:", stack)

    # Pop elements
    print("Popped:", stack.pop())
    print("Popped:", stack.pop())

    # Peek element
    if stack:
    print("Top Element:", stack[-1])

    # Final Stack
    print("Stack after operations:", stack)
    Copied!

    Using collections.deque

    deque from the collections module is optimized for fast appends and pops, making it more efficient for large stacks.

  1. Stacks - Past Year Questions and MCQ - Computer Science Class 12

    Do you want to practice and ...

  2. 30+ Important Questions Stack in Python Class 12 Computer Science …

    Missing:
    • Sample Programs
    Must include:
      • Question 1 – Definition / Theory-Based. (i) What is Data Structure? Answer: Data structure is a way …
      • Question 2 Type A: Programming/Coding Based. Que 1: Ajay has a list containing integers. You …
      • Question 3 Type B: Programming/Coding Based. Que 1: Anjeev has a message (string) that has an …
      • Question 4 – Application-Based. (i) Evaluate the following postfix expression. Show the status of …
      • Question 5 – Conversion (Infix to Postfix) Based. Convert the following infix expression to its …
  3. Class 12 Stack Programs Overview | PDF | Computer …

    The document contains various stack programs implemented in Python, including functionalities for push/pop operations, filtering even numbers, checking for …

  4. Stack in Python - GeeksforGeeks

    Dec 11, 2025 · Python does not have a built-in stack type, but stacks can be implemented in different ways using different data structures, let's look at some …

    Missing:
    • Sample Programs
    Must include:
  5. Computer Science Class 12 –Stack Data Structure Notes (CBSE)

    Jul 8, 2025 · CBSE Class 12 Computer Science Stack 4-mark important questions with sample programs, Python examples, and tips to score full marks. Must-read for boa.

  6. Stacks with Python - W3Schools

    A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. Think of it like a stack of pancakes - you can only add or remove pancakes from the top.

  7. Class 12 CS Python Stack Practice Questions - spsharmaclasses.com

    3. Write a program in Python, with separate user defined functions to perform the following operations on Stack 'City'.

  8. Stack in Python | Class 12 Computer Science CBSE - YouTube

    Sep 15, 2025 · You'll learn basic operations like Push, Pop, Peek/Top, and how stack follows the LIFO (Last In, First Out) principle. We also show how to implement a menu-driven program using a list as a...

    • Author: Technology Planet
    • Views: 211
    Missing:
    • Sample Programs
    Must include:
  9. Class 12 Computer Science Data Structure in Python …

    Dec 6, 2020 · A data structure in python can be defined as a structure which can holds related data. This handout is explained the concept of data structure in a …

    Missing:
    • Sample Programs
    Must include:
  10. Implementation of Stack in Python using List - GeeksforGeeks

    Jul 23, 2025 · Creating a Class and Implementing Stack Method In this example, we will implement a stack class and we will implement all the stack opertion like push, pop, top, empty, and size by the …

    Missing:
    • Sample Programs
    Must include:
  11. People also ask
    Loading
    Unable to load answer