15 Objective Type Questions on Data Structures in Python

15 Objective Type Questions on Data Structures in Python | Global Ranker

15 Objective Type Questions on Data Structures in Python

Author: Global Ranker • Updated: Sep 14, 2025

Python coding banner

Test your knowledge with these 15 multiple-choice questions on Python Data Structures. Each question comes with the correct answer and a short explanation. Perfect for interview preparation, competitive exams, or self-learning.

1. Which of the following is a mutable data type in Python?

A) Tuple
B) String
C) List
D) FrozenSet

Answer: C) List

Lists can be modified after creation (add, remove, change elements). Tuples, strings, and frozensets are immutable.

2. What is the time complexity of accessing an element by index in a Python list?

A) O(1)
B) O(log n)
C) O(n)
D) O(n log n)

Answer: A) O(1)

Python lists are implemented as dynamic arrays, so index-based access is constant time.

3. Which data structure follows the LIFO principle?

A) Queue
B) Stack
C) Dictionary
D) Set

Answer: B) Stack

Stack uses Last In, First Out — the last element added is the first to be removed.

4. Which of these is NOT a valid list method?

A) append()
B) pop()
C) enqueue()
D) insert()

Answer: C) enqueue()

enqueue() is used in queues, not Python lists. Lists use append(), pop(), insert(), etc.

5. In Python 3.7+, which data type preserves insertion order?

A) dict
B) set
C) list
D) tuple

Answer: A) dict

From Python 3.7 onwards, dictionaries preserve insertion order of keys.

6. Which keyword is used to delete an element from a list by index?

A) remove
B) del
C) pop
D) discard

Answer: B) del

The del keyword deletes elements at a specific index, while remove() deletes by value.

7. Which collection type stores unique values only?

A) List
B) Tuple
C) Set
D) Dictionary

Answer: C) Set

Sets in Python only store unique, unordered elements.

8. Which method is used to add multiple elements to a set?

A) append()
B) extend()
C) update()
D) insert()

Answer: C) update()

update() adds multiple elements to a set, while add() inserts a single element.

9. Which data structure uses FIFO principle?

A) Stack
B) Queue
C) Dictionary
D) Set

Answer: B) Queue

Queues follow First In, First Out — the first element added is the first to be removed.

10. Which of these is used as a key in a Python dictionary?

A) Mutable objects
B) Immutable objects
C) Both
D) None

Answer: B) Immutable objects

Dictionary keys must be hashable, hence immutable types like strings, tuples, and numbers are allowed.

11. Which function returns the number of elements in a list?

A) count()
B) length()
C) len()
D) size()

Answer: C) len()

The built-in len() function returns the number of items in a list or other container.

12. What does the pop() method do in lists?

A) Removes first element
B) Removes last element
C) Removes element at index
D) Both B and C

Answer: D) Both B and C

pop() without arguments removes the last element. With an index, it removes that specific element.

13. Which method is used to combine two dictionaries in Python 3.9+?

A) update()
B) merge()
C) union()
D) |

Answer: D) |

From Python 3.9, dictionaries can be merged using the | operator.

14. Which of the following creates a shallow copy of a list?

A) list.copy()
B) list[:]
C) copy.copy(list)
D) All of the above

Answer: D) All of the above

All listed methods produce a shallow copy of a list.

15. Which operator is used to check membership in lists, sets, and tuples?

A) in
B) has
C) contains
D) include

Answer: A) in

The in operator checks whether a value exists within a sequence or collection.

Final Thoughts

These 15 objective type questions cover Python lists, tuples, sets, dictionaries, and common operations. Practice them regularly to improve your understanding of data structures in Python.

Post a Comment

0 Comments