Skip to content

Remainder after division — modulo (math_modulo)

What it does: Returns the remainder after division by A mod B.

math_modulo

Inputs

  • DIVIDEND (A), DIVISOR (B).

Output

  • number

Tips

  • Beware of negative numbers — the behavior of the module is defined but can be counterintuitive.
  • The generator returns the expression A % B directly; at B = 0 Python throws an exception.

When to use it

For alternating multiple states or divisibility test. The expression pocet % 2 == 0 recognizes an even number; pocet % 4 cycles through 0, 1, 2, and 3 for a non-negative counter.

For negative numbers, the sign of the divisor matters: -5 % 3 is 1, while 5 % -3 is -1.