//
is floor division: it divides and rounds down, though it still produces a float if the operands are floats. In Python 2, it's the same as regular division for integers, unless you use from __future__ import division
to get Python 3's "true" division behavior.
So, yes, this is a little complicated. Essentially it exists to recreate the behavior you get in Python 2 by dividing two integers, because that changes in Python 3.
In Python 2:
11 / 5
→ 2
11.0 / 5.0
→ 2.2
11 // 5
→ 2
11.0 // 5.0
→ 2.0
In Python 3, or Python 2 with from __future__ import division
, or Python 2 run with -Q new
:
11 / 5
→ 2.2
11.0 / 5.0
→ 2.2
11 // 5
→ 2
11.0 // 5.0
→ 2.0
And, of course, adding the =
just turns it into a combo assignment operator like /=
.