ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
x = 10
y = x
y += 1
z = [x]
z[0] += 5
print(x, y, z)
  1. A. 10 11 [15]
  2. B. 11 11 [15]
  3. C. 10 11 [10]
  4. D. 10 11 [11]

Correct answer: A. 10 11 [15]

Integers are immutable, so y += 1 rebinds y and leaves x at 10. z holds the value 10 and z[0] += 5 changes the list to [15].

More Python Programming questions

Exams that ask this topic