KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

What will be the output of the following Python code?

x = [1, 2, 3, 4]
x.append([5, 6]) 
print(x)

Python List Manipulation

1 Like

Answer

[1, 2, 3, 4, [5, 6]]

Working

The append() method adds the given element as a single item at the end of the list. Here, [5, 6] is a list, so it is added as a nested list, not as individual elements. Hence, the final list becomes [1, 2, 3, 4, [5, 6]].

Answered By

3 Likes


Related Questions