Top 15 Objective Type Questions on Data Structures in Python (With Answers)

Top 15 Objective Type Questions on Data Structures in Python

Top 15 Objective Type Questions on Data Structures in Python

Python programming illustration

Data Structures are one of the most important topics in Python programming. Whether you are preparing for an interview, an exam, or just want to test your knowledge, these objective type questions will help you. Each question comes with an answer and explanation.

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

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

Answer: B) List

Lists can be modified after creation, unlike tuples, strings, or frozensets.

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

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

Answer: A) O(1)

Python lists are dynamic arrays; index access is constant time.

3. Which data structure in Python follows Last In First Out (LIFO)?

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

Answer: B) Stack

Stacks use LIFO; lists can work as stacks with append() and pop().

4. In Python, which of the following is NOT a valid list method?

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

Answer: C) enqueue()

enqueue() is for queues, not Python lists.

5. Which of these preserves insertion order from Python 3.7+?

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

Answer: A) dict

From Python 3.7+, dicts preserve insertion order by default.

6. What does the method set().add() do?

A) Adds one element
B) Adds multiple elements
C) Sorts the set
D) Deletes an element

Answer: A) Adds one element

add() inserts a single element into a set.

7. Which of these is a key-value data structure in Python?

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

Answer: C) Dictionary

Dictionaries store data in key-value pairs.

8. Which method removes all elements from a list?

A) pop()
B) clear()
C) remove()
D) del

Answer: B) clear()

clear() empties a list completely.

9. Which data structure is best for implementing a queue in Python?

A) List
B) Set
C) collections.deque
D) Dictionary

Answer: C) collections.deque

deque allows fast append/pop from both ends, perfect for queues.

10. Which of these is immutable?

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

Answer: C) Tuple

Tuples cannot be modified after creation.

11. Which operator is used to concatenate two lists?

A) *
B) +
C) &
D) %

Answer: B) +

The + operator joins two lists.

12. What is returned by len({1,2,2,3})?

A) 4
B) 3
C) Error
D) None

Answer: B) 3

Sets remove duplicates, so {1,2,2,3} → {1,2,3}.

13. Which list method sorts elements in ascending order?

A) sort()
B) order()
C) sorted()
D) arrange()

Answer: A) sort()

sort() sorts the list in place; sorted() returns a new sorted list.

14. Which method is used to get all keys of a dictionary?

A) values()
B) items()
C) keys()
D) get()

Answer: C) keys()

keys() returns all keys in a dictionary.

15. What is the output of bool([])?

A) True
B) False
C) []
D) None

Answer: B) False

Empty containers evaluate to False in Python.

Developer coding illustration

Post a Comment

0 Comments