python - why does x -= x + 4 return -4 instead of 4 -
new python , trying wrestle finer points of assignment operators. here's code , question.
x = 5 print(x) x -= x + 4 print(x)
the above code, returns 5 first time, yet -4 upon second print. in head feel number should 4 reading x= x - x +4. however, know wrong python returning -4 instead. gracious if explain me (in simple terms novice) have been pounding head on table on one.
x -= x + 4
can written as:
x = x - (x + 4) = x - x - 4 = -4
Comments
Post a Comment