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 % rightParameters & Attributes
| Name | Type | Description |
|---|---|---|
| left | real number or formatting string or supporting object | Real numeric dividend or format string. |
| right | real number or format arguments or supporting object | Nonzero 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)