0
Python challenge question
In a py challenge, x = 5 x, x = x+1, x+2 print (x) //Outputs 7. Why not 8?? I think I should clarify it a bit. The result of above written code is 7 and not 8. I want to know why it outputs 7 and not 8 ???
6 Answers
+ 2
Because right side (tuple) calculates first
x, x = 6, 7
and then tuple unpacking
+ 1
I'm very sure Google is hunting out the quiz maker right now for interviews ...
The first question of the interview will be ...
"What did you have for breakfast ...eggs or spam?"
Sorry Roy, just couldn't help wonder where such riddle educate us in coding đ€
+ 1
Oh it was my mistake. So the correct answer is that ... In python, tuples assign the values in the right to the left. In simple words, when u wrote the code:
x,x = x+1, x+2
Python at first evaluated x+1 and x+2. So the code now is:
x,x = 6,7
And now since python is an interpreted language it first took the value of x as 6 and then changed it to 7 .. Hope I'm correctđ
0
âBHâY I think you misunderstood my question. I have edited it a bit for clarity. Kindly go through it
0
Because the newest value of variable iterates the old value in Python.
0
Amrit Mishra Can you please elaborate on what you just said. Please.