What is the output of the following code? “`python x = [1, 2, 3] y = x y.append(4) print(x) “`

Python Developer Hard

Python Developer — Hard

What is the output of the following code? “`python x = [1, 2, 3] y = x y.append(4) print(x) “`

Key points

  • Assigning a list to another variable does not create a new copy
  • Modifying one variable also affects the other
  • Appending to y also appends to x

Ready to go further?

Related questions