CBSE Class 12 Computer Science Question 30 of 105

Python Revision Tour II — Question 9

Back to all questions
9
Question

Question 9

List AL is defined as follows : AL = [1, 2, 3, 4, 5]
Which of the following statements removes the middle element 3 from it so that the list AL equals [1, 2, 4, 5] ?

  1. del AL[2]
  2. AL[2:3] = []
  3. AL[2:2] = []
  4. AL[2] = []
  5. AL.remove(3)
Answer

del AL[2]
AL[2:3] = []
AL.remove(3)

Reasondel AL[2] — The del keyword deletes the element from the list AL from index 2.
AL[2:3] = [] — The slicing of the list AL[2:3] begins at index 2 and ends at index 2. Therefore, the element at index 2 will be replaced by an empty list [].
AL.remove(3) — The remove() function removes an element from the list AL from index 3."