You are correct that **
is the power function.
^
is bitwise XOR.
%
is indeed the modulus operation, but note that for positive numbers, x % m = x
whenever m > x
. This follows from the definition of modulus. (Additionally, Python specifies x % m
to have the sign of m
.)
//
is a division operation that returns an integer by discarding the remainder. This is the standard form of division using the /
in most programming languages. However, Python 3 changed the behavior of /
to perform floating-point division even if the arguments are integers. The //
operator was introduced in Python 2.6 and Python 3 to provide an integer-division operator that would behave consistently between Python 2 and Python 3. This means:
| context | `/` behavior | `//` behavior |
---------------------------------------------------------------------------
| floating-point arguments, Python 2 & 3 | float division | int divison |
---------------------------------------------------------------------------
| integer arguments, python 2 | int division | int division |
---------------------------------------------------------------------------
| integer arguments, python 3 | float division | int division |
For more details, see this question: Division in Python 2.7. and 3.3