Lists Questions and Answers
Practice ModeShowing 10 of 25 questions
Q11
How do you sort a list in descending order?
Answer: Option A
Explanation: sort() with reverse=True parameter sorts the list in descending order.
Q12
What is list comprehension in Python?
Answer: Option C
Explanation: List comprehension provides a concise way to create lists based on existing iterables.
Q13
How do you check if an element exists in a list?
Answer: Option C
Explanation: The "in" operator is used to check membership in a list.
Q14
What is the result of [1, 2, 3] * 3?
Answer: Option C
Explanation: The * operator with lists performs repetition, not multiplication.
Q15
How do you count occurrences of an element in a list?
Answer: Option B
Explanation: The count() method returns the number of times the specified element appears in the list.
Q16
What does the insert() method do?
Answer: Option B
Explanation: insert() adds an element at a specific position in the list, shifting other elements to the right.
Q17
How do you remove all elements from a list?
Answer: Option C
Explanation: The clear() method removes all items from the list, leaving it empty.
Q18
What is the difference between sort() and sorted()?
Answer: Option C
Explanation: sort() modifies the original list in-place, while sorted() returns a new sorted list without modifying the original.
Q19
How do you create a list with numbers from 0 to 9?
Answer: Option B
Explanation: range(10) generates numbers from 0 to 9, and list() converts it to a list.
Q20
What is the result of "python" in ["java", "python", "c++"]?
Answer: Option A
Explanation: The "in" operator checks for exact match in the list elements.