ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
x = 1
x, y = x + 1, x * 10
print(x, y)
  1. A. 2 2
  2. B. 1 10
  3. C. 2 10
  4. D. 2 20

Correct answer: C. 2 10

The whole right-hand side is evaluated before anything is assigned, using the old x = 1: (1 + 1, 1 * 10) = (2, 10). Only then are x and y bound.

More Python Programming questions

Exams that ask this topic