Lists Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q11
How do you sort a list in descending order?
  • A list.sort(reverse=True)
  • B list.descend()
  • C list.reverse_sort()
  • D sorted(list, order="desc")
Answer: Option A
Explanation: sort() with reverse=True parameter sorts the list in descending order.
Q12
What is list comprehension in Python?
  • A A method to understand list contents
  • B A way to document lists
  • C A concise way to create lists
  • D A list analysis tool
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?
  • A contains()
  • B exists()
  • C in
  • D has()
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?
  • A [3, 6, 9]
  • B [[1,2,3], [1,2,3], [1,2,3]]
  • C [1, 2, 3, 1, 2, 3, 1, 2, 3]
  • D Error
Answer: Option C
Explanation: The * operator with lists performs repetition, not multiplication.
Q15
How do you count occurrences of an element in a list?
  • A occurrences()
  • B count()
  • C frequency()
  • D find_all()
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?
  • A Adds element at beginning
  • B Adds element at specified index
  • C Replaces element at index
  • D Inserts a new list
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?
  • A delete()
  • B remove_all()
  • C clear()
  • D empty()
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()?
  • A No difference
  • B sort() works on strings, sorted() on numbers
  • C sort() modifies original, sorted() returns new list
  • D sorted() is faster
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?
  • A list(0,9)
  • B list(range(10))
  • C [0-9]
  • D list(10)
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++"]?
  • A True
  • B False
  • C Error
  • D None
Answer: Option A
Explanation: The "in" operator checks for exact match in the list elements.
Questions and Answers for Competitive Exams Various Entrance Test