MCQs on Data Structures | Python programming

1. Lists

  1. Which of the following is the correct way to create a list in Python?
    • a) list = ()
    • b) list = []
    • c) list = {}
    • d) list = <>
  2. How do you access the first element of a list my_list = [1, 2, 3]?
    • a) my_list[1]
    • b) my_list(0)
    • c) my_list[0]
    • d) my_list[0:]
  3. Which method is used to add an element at the end of a list?
    • a) append()
    • b) insert()
    • c) extend()
    • d) add()
  4. How do you modify an element at index 2 in a list my_list = [1, 2, 3]?
    • a) my_list[2] = 5
    • b) my_list(2) = 5
    • c) my_list[3] = 5
    • d) my_list.append(5)
  5. What is the method to remove an element from a list by value?
    • a) remove()
    • b) pop()
    • c) del()
    • d) clear()

2. Creation, Accessing, and Modifying Lists

  1. Which of the following will return the length of a list in Python?
    • a) len(list)
    • b) list.size()
    • c) list.length()
    • d) size(list)
  2. What will be the output of the following code: my_list = [1, 2, 3, 4]; print(my_list[2:])?
    • a) [2, 3, 4]
    • b) [3, 4]
    • c) [1, 2, 3]
    • d) [2, 3]
  3. Which method is used to remove an element from a list by index?
    • a) pop()
    • b) remove()
    • c) del()
    • d) clear()
  4. What will the following code output: my_list = [1, 2, 3]; print(my_list[::-1])?
    • a) [1, 2, 3]
    • b) [3, 2, 1]
    • c) [2, 1, 3]
    • d) IndexError
  5. How do you concatenate two lists in Python?
    • a) list1 + list2
    • b) list1.append(list2)
    • c) list1.extend(list2)
    • d) list1.insert(list2)

3. List Methods and Operations

  1. Which method is used to add an element at a specific index in a list?
    • a) insert()
    • b) append()
    • c) add()
    • d) extend()
  2. How do you count the occurrences of an element in a list?
    • a) count()
    • b) find()
    • c) index()
    • d) search()
  3. Which method is used to remove all elements from a list?
    • a) clear()
    • b) remove()
    • c) del()
    • d) pop()
  4. How do you reverse the elements of a list?
    • a) reverse()
    • b) sort()
    • c) reversed()
    • d) reverse_elements()
  5. Which operation checks if an item exists in a list?
    • a) in
    • b) ==
    • c) contains()
    • d) has()

4. Tuples

  1. How do you define a tuple in Python?
    • a) tuple = []
    • b) tuple = ()
    • c) tuple = {}
    • d) tuple = <>
  2. Which of the following statements is true about tuples in Python?
    • a) Tuples are mutable
    • b) Tuples are immutable
    • c) Tuples cannot store different data types
    • d) Tuples cannot store duplicates
  3. How do you access the second element of a tuple my_tuple = (10, 20, 30)?
    • a) my_tuple(2)
    • b) my_tuple[1]
    • c) my_tuple[2]
    • d) my_tuple[0]
  4. What is the method used to find the index of an element in a tuple?
    • a) index()
    • b) search()
    • c) locate()
    • d) find()
  5. How do you concatenate two tuples?
    • a) tuple1 + tuple2
    • b) tuple1.append(tuple2)
    • c) tuple1.insert(tuple2)
    • d) tuple1.extend(tuple2)

5. Creation, Accessing, and Modifying Tuples

  1. How do you convert a tuple to a list?
    • a) list()
    • b) tuple()
    • c) convert()
    • d) to_list()
  2. Which of the following will result in a TypeError?
    • a) my_tuple[0] = 5
    • b) my_tuple[0]
    • c) tuple1 + tuple2
    • d) len(my_tuple)
  3. What happens if you try to modify an element in a tuple?
    • a) It will be modified successfully
    • b) It will throw a TypeError
    • c) It will be ignored
    • d) It will modify the tuple globally
  4. How do you count the occurrences of an element in a tuple?
    • a) count()
    • b) find()
    • c) index()
    • d) count_elements()
  5. How do you remove an element from a tuple?
    • a) del()
    • b) pop()
    • c) remove()
    • d) Tuples are immutable and cannot be changed

6. Dictionaries

  1. How do you define a dictionary in Python?
    • a) dict = []
    • b) dict = ()
    • c) dict = {}
    • d) dict = <>
  2. What is the method used to add a key-value pair to a dictionary?
    • a) insert()
    • b) add()
    • c) put()
    • d) dict[key] = value
  3. How do you access a value from a dictionary using a key?
    • a) dict.key
    • b) dict(key)
    • c) dict[key]
    • d) dict.get(key)
  4. Which method returns a list of keys in a dictionary?
    • a) keys()
    • b) values()
    • c) items()
    • d) list()
  5. How do you remove a key-value pair from a dictionary?
    • a) pop()
    • b) remove()
    • c) del()
    • d) clear()

Answers (Tabular Form)

Question No.Answer
1b
2c
3a
4a
5a
6a
7a
8a
9b
10a
11a
12a
13a
14a
15a
16b
17b
18b
19a
20a
21a
22a
23b
24a
25d
26c
27d
28c
29a
30a

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top