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
Mention any two types of cyber threats.
How does data acquisition play a key role in Artificial Intelligence project cycle?
What will be the output of the following Python code?
a = "hello" b = "world" print(a + b)What will be the output of the following Python code?
x = {1: 'apple', 2: 'banana'} x[3] = "cherry" print(x)