operator precedence of floor division and division

  • A+

I have trouble understanding why python returns different results for these 2 statements:

-1 // 3/4 and -1 // 0.75

The first one returns -0.25 and the second on returns -2.

The way i understand it, the / operator is executed before // , thus those 2 statements should have the same result.

edit: I was referring to a document provided by my university. I misinterpreted that. Official python documentation proves me wrong. Thanks for all the quick answers.


The / and // operators have the same precedence according to the documentation so they are evaluated from left to right when used in the same expression. -1 // 3/4 is therefore equivalent to (-1 // 3)/4 rather than -1 // (3/4).


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: