CBSE Class 11 Computer Science Question 28 of 98

Python Programming Fundamentals — Question 7

Back to all questions
7
Question

Question 7

What will be the output of the following snippet?

x, y = 2, 6
x, y = y, x + 2
print(x, y)
  1. 6 6
  2. 4 4
  3. 4 6
  4. 6 4
Answer

6 4

Reason — Initially, x is assigned the value 2, and y is assigned 6 using multiple assignments. Then, the expression y, x + 2 is evaluated, where y is 6, and x + 2 calculates to 4. After evaluating the right-hand side, x is reassigned to y, making x equal to 6, and y is reassigned to x + 2, making y equal to 4. Thus, when print(x, y) executes, it outputs 6 4, showing the final values after the assignments.