Python Arrays Questions and Answers
Practice ModeShowing 10 of 25 questions
Q21
How do you concatenate two lists?
Answer: Option A
Explanation: The + operator concatenates lists creating a new list. extend() method also concatenates but modifies the first list in-place.
Q22
What is the time complexity of the count() method?
Answer: Option A
Explanation: count() has to traverse the entire list to count occurrences of a value, resulting in O(n) time complexity where n is the list length.
Q23
How do you insert an element at a specific position?
Answer: Option A
Explanation: insert(index, element) method inserts the element at the specified index, shifting subsequent elements to the right. Time complexity is O(n).
Q24
What is a shallow copy vs deep copy?
Answer: Option A
Explanation: Shallow copy creates a new list but references the same objects. Deep copy creates a new list and recursively copies all nested objects.
Q25
How do you convert a list to a tuple?
Answer: Option A
Explanation: tuple(list) constructor creates a tuple with the same elements as the list. Tuples are immutable unlike lists.