30+ MCQs on Python List Manipulation

Ayushi Trivedi Last Updated : 25 Feb, 2024
7 min read

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!

 Python List Manipulation

30+ MCQs on Python List Manipulation

Q1. Which of the following methods is used to add an element to the end of a list in Python?

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.

Q2. What is the output of the following Python code snippet?

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).

Q3. Which of the following methods is used to remove the first occurrence of a specified element from a list in Python?

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.

Q4. What will be the output of the following Python code snippet?

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).

Q5. Which of the following methods is used to reverse the elements of a list in Python?

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.

Q6. What is the output of the following Python code snippet?

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.

Q7. Which of the following methods is used to sort the elements of a list in Python?

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.

Q8. What will be the output of the following Python code snippet?

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.

Q9. Which of the following methods is used to insert an element at a specified position in a list in Python?

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.

Q10. What is the output of the following Python code snippet?

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.

Q11. Which of the following methods is used to remove the element at a specified position in a list in Python?

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.

Q12. What will be the output of the following Python code snippet?

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.

Q13. Which of the following methods is used to count the number of occurrences of a specified element in a list in Python?

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.

Q14. What will be the output of the following Python code snippet?

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.

Q15. Which of the following methods is used to create a shallow copy of a list in Python?

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.

Q16. What will be the output of the following Python code snippet?

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.

Q17. Which of the following methods is used to clear all elements from a list in Python?

a) clear()

b) empty()

c) remove_all()

d) erase()

Answer: a

Explanation: The clear() method removes all elements from the list.

Q18. What will be the output of the following Python code snippet?

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.

Q19. Which of the following methods is used to find the index of the first occurrence of a specified element in a list in Python?

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.

Q20. What will be the output of the following Python code snippet?

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.

Q21. Which of the following methods is used to concatenate two lists in Python?

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.

Q22. What will be the output of the following Python code snippet?

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.

Q23. Which of the following methods is used to reverse the order of elements in a list in Python?

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.

Q24. What will be the output of the following Python code snippet?

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.

Q25. Which of the following methods is used to sort the elements of a list in descending order in Python?

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.

Q26. What will be the output of the following Python code snippet?

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.

Q27. Which of the following methods is used to remove the element with the highest value from a list in Python?

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.

Q28. What will be the output of the following Python code snippet?

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.

Q29. Which of the following methods is used to remove all occurrences of a specified element from a list in Python?

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.

Q30. What will be the output of the following Python code snippet?

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.

Q31. What does the following Python code snippet do?

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.

Q32. What is the output of the following Python code snippet?

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.

Q33. What will be the output of the following Python code snippet?

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:

My name is Ayushi Trivedi. I am a B. Tech graduate. I have 3 years of experience working as an educator and content editor. I have worked with various python libraries, like numpy, pandas, seaborn, matplotlib, scikit, imblearn, linear regression and many more. I am also an author. My first book named #turning25 has been published and is available on amazon and flipkart. Here, I am technical content editor at Analytics Vidhya. I feel proud and happy to be AVian. I have a great team to work with. I love building the bridge between the technology and the learner.

Responses From Readers

Clear

Congratulations, You Did It!
Well Done on Completing Your Learning Journey. Stay curious and keep exploring!

We use cookies essential for this site to function well. Please click to help us improve its usefulness with additional cookies. Learn about our use of cookies in our Privacy Policy & Cookies Policy.

Show details