Python Programming - Lists

Exercise : Lists - General Questions
  • Lists - General Questions
41.
What is the purpose of the insert() method in Python lists?
Appends an element at the end of the list.
Inserts an element at a specified index in the list.
Removes the first occurrence of a specific element.
Deletes an element at a specified index in the list.
Answer: Option
Explanation:
The insert() method is used to insert an element at a specified index in the list.

42.
How can you find the length of a list in Python?
length(list)
list.length()
len(list)
list.size()
Answer: Option
Explanation:
The len() function is used to find the length of a list in Python.

43.
What will the list.pop(2) method do?
Removes the element at index 2.
Removes the element with the value 2.
Raises an error because index 2 does not exist.
Removes all occurrences of the value 2.
Answer: Option
Explanation:
The pop() method removes and returns the element at the specified index.

44.
How can you check if a list contains only numeric elements in Python?
all(isinstance(x, int) for x in my_list)
my_list.isnumeric()
numeric(my_list)
if my_list.has_numbers()
Answer: Option
Explanation:
Using all() with isinstance() checks if all elements in the list are of type int.

45.
What is the purpose of the list.reverse() method in Python?
Sorts the list in ascending 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.