Search Tutorials


Python List MCQ Questions and Answers | JavaInUse

Python List MCQ Questions and Answers

Q. What is the list data structure in Python used for?

A. Storing and manipulating data in a linear sequence
B. Efficiently storing and retrieving key-value pairs
C. Creating complex data structures like trees and graphs
D. Performing mathematical operations on large data sets

Q. How do you create an empty list in Python?

A. list()
B. []
C. {}
D. None of the above

Q. How can you access the last element of a list named my\_list?

A. my_list[0]
B. my_list[-1]
C. my_list.last
D. my_list[len(my_list) - 1]

Q. What is the output of len([1, 2, 3, 4, 5])?

A. 5
B. 10
C. [1, 2, 3, 4, 5]
D. None of the above

Q. How can you add elements to the end of a list?

A. Using the append() method
B. Using the extend() method
C. Using the insert() method
D. All of the above

Q. What is the output of [1, 2, 3] + [4, 5, 6]

A. [1, 2, 3, 4, 5, 6]
B. [4, 5, 6]
C. [1, 2, 3]
D. None of the above

Q. How can you remove the first occurrence of a value from a list?

A. Using the remove() method
B. Using the pop() method
C. Using the del keyword
D. All of the above

Q. What is the output of sorted([3, 1, 4, 1, 5])?

A. [1, 1, 3, 4, 5]
B. [3, 1, 4, 1, 5]
C. [1, 3, 4, 5]
D. None of the above

Q. How can you count the number of occurrences of a value in a list?

A. Using the count() method
B. Using a for loop
C. Using the len() function
D. None of the above

Q. What is list comprehension in Python?

A. A concise way to create lists by applying an expression to each item in an iterable
B. A method to iterate over lists and perform computations
C. A technique for sorting lists in ascending order
D. A function that returns the length of a list

Q. How can you create a list of squares of numbers from 1 to 5 using list comprehension?

A. [x**2 for x in range(1, 6)]
B. [x*x for x in [1, 2, 3, 4, 5]]
C. [x**2 for x in [1, 2, 3, 4, 5]]
D. None of the above

Q. What is the output of [x/2 for x in [2, 4, 6, 8]]?

A. [1, 2, 3, 4]
B. [0.5, 1, 1.5, 2]
C. [2, 4, 6, 8]
D. None of the above

Q. How can you create a nested list with list comprehension?

A. [[x] for x in range(5)]
B. [x for x in range(5) for y in range(5)]
C. [[x, y] for x in range(5) for y in range(5)]
D. None of the above

Q. What is the output of [x for x in "hello"]?

A. ['h', 'e', 'l', 'l', 'o']
B. ['hello']
C. ['h', 'e', 'l', 'o']
D. None of the above

Q. How can you create a list of odd numbers from 1 to 9 using list comprehension and the % operator?

A. [x for x in range(1, 10) if x % 2 != 0]
B. [x for x in range(1, 10) if x % 2 == 0]
C. [x for x in range(1, 10) if x < 5]
D. None of the above

Q. What is the list data structure in Python used for?

A. Storing and manipulating data in a linear sequence
B. Efficiently storing and retrieving key-value pairs
C. Creating complex data structures like trees and graphs
D. Performing mathematical operations on large datasets

Q. How do you create an empty list in Python?

A. my_list = []
B. my_list = list()
C. my_list = {}
D. my_list = set()

Q. How do you access the first element of a list named my_list?

A. my_list.first
B. my_list[0]
C. my_list.get(0)
D. my_list.head

Q. What is the output of len([1, 2, 3, 4, 5])?

A. 5
B. [1, 2, 3, 4, 5]
C. 1
D. None of the above

Q. How do you add elements to the end of a list?

A. Using the append() method
B. Using the insert() method
C. Using the extend() method
D. All of the above

Q. What is the output of [1, 2, 3] + [4, 5, 6]

A. [1, 2, 3, 4, 5, 6]
B. [4, 5, 6]
C. [1, 2, 3]
D. None of the above

Q. How do you remove the first occurrence of an element from a list?

A. Using the remove() method
B. Using the pop() method
C. Using the delete() method
D. Using the clear() method

Q. What is the output of len(list(range(5)))?

A. 5
B. [0, 1, 2, 3, 4]
C. 0
D. None of the above

Q. How do you insert an element at a specific index in a list?

A. Using the insert() method
B. Using the append() method
C. Using the add() method
D. Using the extend() method

Q. What is the output of ['a', 'b', 'c'] * 3?

A. ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']
B. ['a', 'b', 'c']
C. ['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c']
D. None of the above

Q. How do you remove all occurrences of an element from a list?

A. Using a for loop and the remove() method
B. Using the clear() method
C. Using a while loop and the remove() method
D. Using a list comprehension and the remove() method

Q. What is the output of sorted([3, 1, 4, 1, 5])?

A. [1, 1, 3, 4, 5]
B. [3, 1, 4, 1, 5]
C. [5, 4, 3, 1, 1]
D. None of the above

Q. How do you reverse the order of elements in a list?

A. Using the reverse() method
B. Using the sort() method
C. Using the flip() method
D. Using the rearrange() method

Q. What is the output of ['a', 'b', 'c'].count('b')?

A. 1
B. 0
C. 2
D. None of the above

Q. How do you create a shallow copy of a list?

A. Using the copy() method
B. Using the clone() method
C. Using the duplicate() method
D. Using the deepcopy() method