operator precedence of floor division and division
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)
.
The way i understand it, the
/
operator is executed before//
, thus those 2 statements should have the same result.
Your understanding is incorrect. /
and //
have the same precedence and have left associativity, meaning that Python performs the leftmost operation first - in your case, the /
.
The Expressions documentation has a section about Operator Precedence. Operators in the same box have the same precedence.
Thus, the table tells you that //
and /
have equal precedence, so
-1 // 3/4
parses as
>>> (-1//3)/4>>> -0.25