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

Python Medium
Select the correct answer: Single Choice

Key points

  • Assigning a list to another variable creates a reference, not a copy
  • Modifying one variable affects the other due to shared memory
  • Appending to y also appends to x in this scenario

Ready to go further?