Python Programming - Lists

Exercise : Lists - General Questions
  • Lists - General Questions
6.
Which of the following methods is used to insert an element at a specific index in a list?
add(index, element)
insert(index, element)
append(index, element)
push(index, element)
Answer: Option
Explanation:
The insert(index, element) method is used to insert an element at a specific index in a list.

7.
How can you reverse the order of elements in a list in Python?
reverse()
list.reverse()
reversed(list)
list.reversed()
Answer: Option
Explanation:
The list.reverse() method is used to reverse the order of elements in a list in-place.

8.
What is the purpose of the count method in Python lists?
To count the number of occurrences of a specific element.
To count the total number of elements in the list.
To count the number of unique elements in the list.
To count the number of elements satisfying a condition.
Answer: Option
Explanation:
The count method in Python lists is used to count the number of occurrences of a specific element.

9.
Which method is used to remove the first occurrence of a specific element from a list?
remove(element)
delete(element)
pop(element)
discard(element)
Answer: Option
Explanation:
The remove(element) method is used to remove the first occurrence of a specific element from a list.

10.
What is the correct way to create a new list by multiplying each element of an existing list by 2 in Python?
new_list = list * 2
new_list = [element * 2 for element in old_list]
new_list = old_list.multiply(2)
new_list = old_list * 2
Answer: Option
Explanation:
The correct way to create a new list by multiplying each element of an existing list by 2 is using a list comprehension as shown in option B.