Python Programming - Lists

Exercise : Lists - General Questions
  • Lists - General Questions
31.
What does the clear() method do in Python lists?
Removes the last element from the list.
Removes all occurrences of a specific element.
Removes all elements from the list.
Removes elements from the list based on a condition.
Answer: Option
Explanation:
The clear() method in Python lists is used to remove all elements from the list, leaving it empty.

32.
What is the purpose of the reverse() method in Python lists?
Sorts the list in descending order.
Reverses the order of elements in the list.
Removes duplicate elements from the list.
Appends the list to itself.
Answer: Option
Explanation:
The reverse() method in Python lists is used to reverse the order of elements in-place.

33.
What is the purpose of the sort() method in Python lists?
Reverses the order of elements.
Sorts the list in ascending order.
Removes duplicate elements.
Appends elements to the end of the list.
Answer: Option
Explanation:
The sort() method in Python lists is used to sort the list in ascending order.

34.
How can you find the average of elements in a numeric list in Python?
average(list)
sum(list) / len(list)
mean(list)
list.average()
Answer: Option
Explanation:
The average of elements in a numeric list is calculated as the sum divided by the number of elements.

35.
How can you create a new list containing only the unique elements from an existing list in Python?
new_list = list.unique()
new_list = list.distinct()
new_list = list(set(list))
new_list = list.remove_duplicates()
Answer: Option
Explanation:
Using set() to remove duplicates and then converting it back to a list creates a new list with unique elements.