Quiz about Python Stack Quiz

Python Stack Quiz

Last Updated :
Discuss
Comments

Question 1

What is the main principle of a stack data structure?

  • A

    FIFO (First In, First Out)


  • B

    Random Access

  • C

    LIFO (Last In, First Out)

  • D

    Priority-based

Question 2

Which Python data structure can be used to implement a stack?

  • A

    Set

  • B

    Dictionary

  • C

    Tuple

  • D

    List

Question 3

How would you implement the "push" operation on a stack in Python?

  • A

    stack.insert(0, element)

  • B

    stack.append(element)

  • C

    stack.add(element)

  • D

    stack.addFront(element)

Question 4

Which Python module provides a stack implementation?

  • A

    collections

  • B

    queue

  • C

    deque

  • D

    heapq

Question 5

Which of the following is the correct way to implement a stack in Python?



  • A

    stack = {}

  • B

    stack = set()

  • C

    stack = ()

  • D

    stack = []

Question 6

Which operation is used to retrieve the top element of a stack without removing it?

  • A

    top()

  • B

    get()

  • C

    view()

  • D

    peek()

Question 7

How do you check if a stack is empty in Python?

  • A

    stack == []

  • B

    len(stack) == 0


  • C

    stack.empty()

  • D

    stack.isEmpty()

Question 8

What will the following code output?

Python
stack = [10, 20, 30, 40]
stack.pop()
stack.append(50)
print(stack)


  • A

    [10, 20, 40, 50]

  • B

    [10, 20, 30, 40, 50]

  • C

    [20, 30, 40, 50]

  • D

    [10, 20, 30, 50]

Question 9

What will the following code output?

Python
stack = [10, 20, 30]
print(stack[-1])


  • A

    20

  • B

    30

  • C

    10

  • D

    Error

Question 10

Which of the following permutation can be obtained in the same order using a stack assuming that input is the sequence 5, 6, 7, 8, 9 in that order?

  • A

    9, 8, 7, 5, 6

  • B

    7, 8, 9, 6, 5

  • C

    5, 9, 6, 7, 8

  • D

    7, 8, 9, 5, 6

There are 13 questions to complete.

Take a part in the ongoing discussion