A

Admin • 833.24K Points
Coach

Q. What will be the output of this code?

Code:
x = [1, 2, 3]
y = x
x.append(4)
print(y)
  • (A) [1, 2, 3]
  • (B) [1, 2, 3, 4]
  • (C) [4]
  • (D) Error
  • Correct Answer - Option(B)
  • Views: 37
  • Filed under category Python
  • Hashtags:

Explanation by: Admin

Both x and y reference the same list object, so changes via x reflect in y.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.