Welcome to the Python List Manipulation MCQs! Lists are versatile data structures in Python, allowing you to store and manipulate collections of items efficiently. These questions will test your knowledge of various list manipulation techniques in Python, including appending, slicing, sorting, and more. Each question is multiple-choice, with only one correct answer. Take your time to carefully read each question and choose the best option. Let’s delve into the world of Python list manipulation together!
a) append()
b) add()
c) insert()
d) extend()
Answer: a
Explanation: The append() method is used to add an element to the end of a list in Python.
my_list = [1, 2, 3, 4, 5]
print(my_list[2:4])
a) [3, 4]
b) [2, 3, 4]
c) [1, 2, 3]
d) [4, 5]
Answer: a
Explanation: Slicing is used to extract a sublist from a list. In this case, it selects elements from index 2 (inclusive) to index 4 (exclusive).
a) remove()
b) pop()
c) delete()
d) discard()
Answer: a
Explanation: The remove() method is used to remove the first occurrence of a specified element from a list in Python.
my_list = [1, 2, 3, 4, 5]
my_list.pop(2)
print(my_list)
a) [1, 2, 4, 5]
b) [1, 2, 3, 5]
c) [1, 2, 4]
d) [1, 2, 3, 4]
Answer: a
Explanation: The pop() method removes and returns the element at the specified index. In this case, it removes the element at index 2 (which is 3).
a) reverse()
b) sort()
c) swap()
d) invert()
Answer: a
Explanation: The reverse() method is used to reverse the elements of a list in Python.
my_list = [1, 2, 3, 4, 5]
my_list.extend([6, 7, 8])
print(my_list)
a) [1, 2, 3, 4, 5, 6, 7, 8]
b) [1, 2, 3, 4, 5, [6, 7, 8]]
c) [1, 2, 3, 4, 5, (6, 7, 8)]
d) [1, 2, 3, 4, 5, {6, 7, 8}]
Answer: a
Explanation: The extend() method adds the elements of the specified iterable to the end of the list.
a) sort()
b) order()
c) arrange()
d) organize()
Answer: a
Explanation: The sort() method is used to sort the elements of a list in Python.
my_list = [3, 2, 1, 4, 5]
my_list.sort()
print(my_list)
a) [1, 2, 3, 4, 5]
b) [5, 4, 3, 2, 1]
c) [3, 2, 1, 4, 5]
d) [1, 3, 2, 4, 5]
Answer: a
Explanation: The sort() method sorts the elements of the list in ascending order by default.
a) insert()
b) add()
c) append()
d) put()
Answer: a
Explanation: The insert() method is used to insert an element at a specified position in a list in Python.
my_list = [1, 2, 3, 4, 5]
my_list.insert(2, 10)
print(my_list)
a) [1, 2, 10, 3, 4, 5]
b) [1, 2, 3, 10, 4, 5]
c) [1, 2, 3, 4, 10, 5]
d) [1, 2, 3, 4, 5, 10]
Answer: a
Explanation: The insert() method inserts the specified element at the specified position in the list.
a) remove()
b) pop()
c) delete()
d) discard()
Answer: b
Explanation: The pop() method removes and returns the element at the specified position in a list in Python.
my_list = [1, 2, 3, 4, 5]
my_list.remove(3)
print(my_list)
a) [1, 2, 4, 5]
b) [1, 2, 3, 4]
c) [1, 2, 4]
d) [1, 2, 5]
Answer: a
Explanation: The remove() method removes the first occurrence of the specified element from the list.
a) count()
b) occurrences()
c) find()
d) search()
Answer: a
Explanation: The count() method returns the number of occurrences of the specified element in the list.
my_list = [1, 2, 2, 3, 4, 2, 5]
print(my_list.count(2))
a) 1
b) 2
c) 3
d) 4
Answer: b
Explanation: The count() method returns the number of occurrences of the specified element in the list.
a) copy()
b) clone()
c) duplicate()
d) replicate()
Answer: a
Explanation: The copy() method is used to create a shallow copy of a list in Python.
my_list = [1, 2, 3]
new_list = my_list.copy()
my_list.append(4)
print(new_list)
a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [1, 2, 3, 4]
d) [1, 2, 3, 4]
Answer: a
Explanation: The copy() method creates a shallow copy of the list. Changes made to the original list do not affect the copied list.
a) clear()
b) empty()
c) remove_all()
d) erase()
Answer: a
Explanation: The clear() method removes all elements from the list.
my_list = [1, 2, 3]
my_list.clear()
print(my_list)
a) []
b) [None]
c) [1, 2, 3]
d) [0, 0, 0]
Answer: a
Explanation: The clear() method removes all elements from the list, leaving it empty.
a) index()
b) find()
c) search()
d) locate()
Answer: a
Explanation: The index() method returns the index of the first occurrence of the specified element in the list.
my_list = [1, 2, 3, 4, 5]
print(my_list.index(3))
a) 2
b) 3
c) 4
d) 5
Answer: a
Explanation: The index() method returns the index of the first occurrence of the specified element in the list.
a) extend()
b) concat()
c) join()
d) merge()
Answer: a
Explanation: The extend() method is used to concatenate two lists in Python by adding all elements of one list to another list.
list1 = [1, 2, 3]
list2 = [4, 5, 6]
list1.extend(list2)
print(list1)
a) [1, 2, 3, 4, 5, 6]
b) [1, 2, 3, [4, 5, 6]]
c) [1, 2, 3, (4, 5, 6)]
d) [1, 2, 3, {4, 5, 6}]
Answer: a
Explanation: The extend() method adds all elements of the second list to the first list, effectively concatenating them.
a) reverse()
b) invert()
c) flip()
d) backward()
Answer: a
Explanation: The reverse() method is used to reverse the order of elements in a list in Python.
my_list = [1, 2, 3, 4, 5]
my_list.reverse()
print(my_list)
a) [1, 2, 3, 4, 5]
b) [5, 4, 3, 2, 1]
c) [5, 4, 3, 2, 1, 0]
d) [1, 2, 3, 4]
Answer: b
Explanation: The reverse() method reverses the order of elements in the list.
a) sort()
b) sort_desc()
c) sort(reverse=True)
d) sort(descending=True)
Answer: c
Explanation: The sort() method accepts a reverse parameter that can be set to True to sort the elements in descending order.
my_list = [5, 2, 8, 1, 3]
my_list.sort(reverse=True)
print(my_list)
a) [5, 2, 8, 1, 3]
b) [1, 2, 3, 5, 8]
c) [8, 5, 3, 2, 1]
d) [1, 3, 5, 8]
Answer: c
Explanation: The sort() method sorts the elements of the list in descending order.
a) pop()
b) remove_max()
c) remove()
d) clear()
Answer: a
Explanation: The pop() method removes and returns the element with the highest index (which is the last element) from the list.
my_list = [1, 2, 3, 4, 5]
my_list.pop()
print(my_list)
a) [1, 2, 3, 4]
b) [1, 2, 3]
c) [2, 3, 4, 5]
d) [1, 2, 3, 4, 5]
Answer: a
Explanation: The pop() method removes and returns the last element from the list.
a) remove_all()
b) delete()
c) remove()
d) clear()
Answer: c
Explanation: The remove() method removes the first occurrence of the specified element from the list.
nums = [1, 2, 3, 4, 5]
result = [x for x in nums if x % 2 == 0]
print(result)
a) [2, 4]
b) [1, 3, 5]
c) [1, 2, 3, 4, 5]
d) [1, 4]
Answer: a
Explanation: This list comprehension filters out even numbers from the list nums
.
words = ["apple", "banana", "orange"]
lengths = [len(word) for word in words]
print(lengths)
a) [5, 6, 6]
b) [“apple”, “banana”, “orange”]
c) [0, 0, 0]
d) [1, 1, 1]
Answer: a
Explanation: This list comprehension creates a new list containing the lengths of each word in the words
list.
numbers = [1, 2, 3, 4, 5]
result = [num * 2 for num in numbers]
print(result)
a) [1, 4, 9, 16, 25]
b) [2, 4, 6, 8, 10]
c) [2, 4, 6, 8, 10]
d) [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
Answer: b
Explanation: This list comprehension doubles each element in the numbers
list.
words = ["apple", "banana", "orange"]
result = [word.upper() for word in words]
print(result)
a) [“APPLE”, “BANANA”, “ORANGE”]
b) [“apple”, “banana”, “orange”]
c) [“Apple”, “Banana”, “Orange”]
d) [“A”, “B”, “O”]
Answer: c
Explanation: This list comprehension converts each word in the words
list to uppercase.
Congratulations on completing the Python List Manipulation MCQs! Lists are essential data structures in Python, offering a wide range of manipulation techniques for working with collections of items. By mastering list manipulation techniques, you gain the ability to perform various tasks such as adding, removing, sorting, and accessing elements within lists efficiently. Keep practicing and experimenting with Python’s list functionalities to become proficient in handling lists within your programs. If you have any questions or want to delve deeper into any topic, don’t hesitate to continue your learning journey. Happy coding!
You can also enroll in our free Python Course Today!
Read our more articles related to MCQs in Python: