Python Programming - Lists

Exercise : Lists - General Questions
  • Lists - General Questions
66.
What is the purpose of the list.count() method in Python?
Returns the total number of elements in the list.
Counts the occurrences of a specific element in the list.
Counts the number of unique elements in the list.
Returns the index of the first occurrence of a specific element.
Answer: Option
Explanation:
The count() method in Python lists is used to count the occurrences of a specific element.

67.
How can you remove all occurrences of a specific element from a list in Python?
list.remove_all(element)
list.delete(element)
list.remove_all_occurrences(element)
list = [x for x in list if x != element]
Answer: Option
Explanation:
Using list comprehension, you can filter out all occurrences of a specific element.

68.
What will the list.reverse() method do in Python?
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.

69.
How can you check if a list is empty in Python?
if list.is_empty()
if len(list) == 0
if list.empty()
if not list
Answer: Option
Explanation:
Checking the length of the list is a common way to determine if it is empty.

70.
What is the purpose of the list.copy() method in Python?
Creates a deep copy of the list.
Creates a shallow copy of the list.
Copies elements from one list to another.
Concatenates two lists.
Answer: Option
Explanation:
The copy() method in Python lists is used to create a shallow copy of the list.