Operators

% — Remainder and percent formatting

For built-in real numbers computes the remainder associated with floor division. For integers a nonzero remainder has the divisor’s sign; float rounding can affect the usual magnitude relationship. Zero divisors raise ZeroDivisionError, and complex values are not supported. With str or bytes on the left, % also supports legacy formatting rather than numeric division. Custom behavior is provided by __mod__ and __rmod__.

Formal Syntax & Structure

python syntaxpython
left % right

Parameters & Attributes

NameTypeDescription
leftreal number or formatting string or supporting objectReal numeric dividend or format string.
rightreal number or format arguments or supporting objectNonzero numeric divisor or formatting arguments.

Return Value

object

Result selected by the operand types and their operation implementations.

Working Example

Example Snippetpython
print(17 % 5)print(-7 % 3)print(7 % -3)print("count=%03d" % 7)
Python Reference