This is one of what we call In-place Operators, which are operators executed jointly with the allocation operator on the object itself (hence the term in-place).
In this case, the operator //=
is nothing more than the operator //
together with the allocation operator =
, being equivalent to:
aux = aux // 10
Assignment operators were defined precisely to avoid the need to type the same object twice within the expression.
The operator //
is known as floor Division because it returns only the entire part of the division between the operands, different from the operator /
, so-called true Division, which returns a floating point number. It is interesting to note that implicitly the operator //
will call the method __ifloordiv__
of its object, then, by making aux //= 10
you implicitly are running aux.__ifloordiv__(10)
, or operator.ifloordiv(aux, 10)
.
Other operators in-place sane:
x += y
, equivalent to x = x + y
x &= y
, equivalent to x = x and y
x <<= y
, equivalent to x = x << y
x %= y
, equivalent to x = x % y
x *= y
, equivalent to x = x * y
x @= y
, equivalent to x = x @ y
x |= y
, equivalent to x = x | y
x **= y
, equivalent to x = x **y
x >>= y
, equivalent to x = x >> y
x -= y
, equivalent to x = x - y
x /= y
, equivalent to x = x / y
x ^= y
, equivalent to x = x ^y
+1 great answer, but what is the name and function of
x @= y
?I saw in the documentation that calls the method__imatmul__
, but in practice it would be useful to?– Luiz Augusto
@Luizaugusto It is for matrix multiplication (matrices). To my knowledge no native object uses this operator, but it exists precisely to allow it to be overloaded in user-defined classes.
– Woss