Lists Questions and Answers
Practice ModeShowing 10 of 25 questions
Q1
Which method is used to add an element to the end of a list in Python?
Answer: Option B
Explanation: The append() method adds a single element to the end of a list.
Q2
How do you access the last element of a list called "my_list"?
Answer: Option C
Explanation: Negative indexing starts from the end of the list, with -1 representing the last element.
Q3
Which method removes and returns the last element from a list?
Answer: Option C
Explanation: The pop() method without any index removes and returns the last element.
Q4
What is the output of len([1, 2, 3, [4, 5]])?
Answer: Option A
Explanation: The len() function counts the total number of elements in the outer list, including the nested list as one element.
Q5
Which method is used to reverse a list in-place?
Answer: Option B
Explanation: The reverse() method modifies the original list and reverses its elements in-place.
Q6
How do you create a shallow copy of a list?
Answer: Option D
Explanation: Slicing with [:] creates a shallow copy of the entire list.
Q7
What does the extend() method do?
Answer: Option B
Explanation: extend() adds all elements from an iterable to the end of the list, extending it.
Q8
How do you find the index of the first occurrence of an element in a list?
Answer: Option C
Explanation: The index() method returns the position of the first occurrence of the specified value.
Q9
Which method removes the first occurrence of a value from a list?
Answer: Option B
Explanation: The remove() method searches for and removes the first occurrence of the specified value.
Q10
What is the difference between append() and extend()?
Answer: Option C
Explanation: append() adds its argument as a single element, while extend() iterates over its argument adding each element.