Python Arrays Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q1
What is the time complexity of accessing an element in a Python list by index?
  • A O(1)
  • B O(n)
  • C O(log n)
  • D O(n²)
Answer: Option A
Explanation: Python lists are implemented as dynamic arrays, allowing O(1) constant time access to elements by index.
Q2
Which method is used to add an element to the end of a Python list?
  • A append()
  • B add()
  • C insert()
  • D push()
Answer: Option A
Explanation: The append() method adds a single element to the end of a list, while extend() adds multiple elements from an iterable.
Q3
What is the output of [1, 2, 3] * 2 in Python?
  • A [1, 2, 3, 1, 2, 3]
  • B [2, 4, 6]
  • C [1, 2, 3, 2]
  • D Error
Answer: Option A
Explanation: The * operator when used with lists performs repetition, creating a new list with elements repeated the specified number of times.
Q4
Which method removes and returns the last element from a list?
  • A pop()
  • B remove()
  • C delete()
  • D cut()
Answer: Option A
Explanation: pop() without an index removes and returns the last element. pop(index) removes and returns the element at the specified position.
Q5
How do you create a copy of a list in Python?
  • A list.copy()
  • B list.clone()
  • C list.duplicate()
  • D list.replicate()
Answer: Option A
Explanation: list.copy() creates a shallow copy. Using slicing [: ] also creates a shallow copy. copy.deepcopy() is needed for nested structures.
Q6
What does the extend() method do in Python lists?
  • A Adds elements from an iterable to the end
  • B Increases the list size by specified number
  • C Extends memory allocation for the list
  • D Creates a new extended list
Answer: Option A
Explanation: extend() takes an iterable as argument and adds all its elements to the end of the list, unlike append() which adds the iterable as a single element.
Q7
Which method returns the index of the first occurrence of an element in a list?
  • A index()
  • B find()
  • C search()
  • D locate()
Answer: Option A
Explanation: index() method returns the position of the first occurrence of the specified value. Raises ValueError if the element is not found.
Q8
What is the time complexity of inserting an element at the beginning of a Python list?
  • A O(n)
  • B O(1)
  • C O(log n)
  • D O(n²)
Answer: Option A
Explanation: Inserting at beginning requires shifting all existing elements, resulting in O(n) time complexity. Use collections.deque for O(1) insertion at both ends.
Q9
How do you reverse a list in-place in Python?
  • A reverse()
  • B reversed()
  • C flip()
  • D invert()
Answer: Option A
Explanation: reverse() method reverses the elements of the list in-place. The reversed() function returns a reverse iterator without modifying the original list.
Q10
What is the difference between remove() and pop() methods?
  • A remove() deletes by value, pop() by index
  • B remove() returns the element, pop() does not
  • C pop() works only for numbers, remove() for all types
  • D There is no difference
Answer: Option A
Explanation: remove() deletes the first occurrence of the specified value, while pop() removes and returns an element at the specified index (last by default).
Questions and Answers for Competitive Exams Various Entrance Test