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

Popular posts from this blog

r - how do you merge two data frames the best way? -

How to debug "expected android.widget.TextView but found java.lang.string" in Android? -

php - mySQL problems with this code? -