remainder

What is left over after whole-number division, given by the % operator: 7 % 2 is 1.

In more detail

n % 2 == 0 is the usual test for an even number. For any numbers, a == (a // b) * b + a % b. In Python the remainder takes the sign of the divisor, so -7 % 2 is 1, which differs from some other languages.

Example

17 % 5   # 2

Related terms

Taught in

References

Certification courses