0

I have this code below for which the output generated is 17 5 but I am unable to figure out why the value of x is 17 after the final interpretation and not 18. Please help me in understanding the logic behind this

x,y=7,2
x,y,x=x+1,y+3,x+10
print(x,y)

Output Generated is : 17 5 Why not 18 5

1 Answers1

2

After the first line, x is 7, y is 2.

In the second line, you are setting x,y,x to x+1,y+3,x+10.

The expressions on the right are evaluated, giving 8,5,17.

You assign 8 to x, 5 to y, and 17 to x.

So at the end, x==17 and y==5.

khelwood
  • 55,782
  • 14
  • 81
  • 108