Python Arrays Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q21
How do you concatenate two lists?
  • A list1 + list2
  • B list1.concat(list2)
  • C list1.join(list2)
  • D list1.merge(list2)
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?
  • A O(n)
  • B O(1)
  • C O(log n)
  • D O(n²)
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?
  • A insert(index, element)
  • B add(index, element)
  • C put(index, element)
  • D set(index, element)
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?
  • A Shallow copies references, deep copies objects
  • B Shallow is faster, deep is slower
  • C Shallow works for 1D, deep for 2D lists
  • D There is no difference
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?
  • A tuple(list)
  • B list.tuple()
  • C convert_to_tuple(list)
  • D list.freeze()
Answer: Option A
Explanation: tuple(list) constructor creates a tuple with the same elements as the list. Tuples are immutable unlike lists.
Questions and Answers for Competitive Exams Various Entrance Test