KnowledgeBoat Logo
|

Informatics Practices

Consider the following lists:

L1 = ["this", "is", "a", "list"]
L2 = ["this", "is", "another list"]

Which of the following statements will result in an error?

  1. L1 = L2
  2. L1.copy()
  3. L2.append(1, 2, 3)
  4. L2.pop()

Python List Manipulation

1 Like

Answer

L2.append(1,2,3)

Reason — The append() method in list takes one argument and adds it as a single element to the end of the list. Using L2.append(1, 2, 3) will result in an error because it provides multiple arguments. The correct statement would be L2.append([1, 2, 3]) to add the entire list [1, 2, 3] as a single element to L2.

Answered By

1 Like


Related Questions