Python Programming - Tricky Questions - Discussion

Discussion Forum : Tricky Questions - General Questions (Q.No. 15)
15.
What is the output of the following Python code?
x = [1, 2, 3]
y = x + [4, 5]
z = x.extend([4, 5])
print(x, y, z)
[1, 2, 3, 4, 5] [1, 2, 3, 4, 5] None
[1, 2, 3] [1, 2, 3, 4, 5] None
[1, 2, 3, 4, 5] [1, 2, 3] None
[1, 2, 3] [1, 2, 3] None
Answer: Option
Explanation:
x is a list with values [1, 2, 3]. y is the result of concatenating x with [4, 5]. z is the result of extending x with [4, 5], but it returns None. The values of x, y, and z are printed. Thus, the output is [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] None.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.