Python — Why is there a difference between `0–3//2` and ` — 3//2`?
How to do floor/ceiling operations without the math
module
1 min readOct 17, 2021
Python uses the symbol -
as both a unary (-x
) and a binary (x-y
) operator. These have different operator precedence.
In specific, the ordering wrt //
is:
- unary
-
- binary
//
- binary
-
By introducing a 0
as 0--3//2
, the first -
is a binary -
and is applied last. Without a leading 0
as --3//2
, both …