Division is defined so that the following is always true
n = q × d + r
where
- n is the numerator (or dividend),
- d != 0 is the denominator (or divisor),
- q is the quotient, and
- r > 0 is the remainder.
(This holds for positive and negative values; q is positive if n and d have the same sign and negative otherwise. r is defined to be always positive.)
In Python, n/d == q
and n % d == r
. If n
is 0, then q
must also be 0, in which case r
must be 0 as well—all independent of the value of d
.
(Off-topic, but note that this also captures the problem with division by 0: for non-zero d, q and r are uniquely determined; for d = 0, any value of q will satisfy the equation for r = n.
0
solved Why does 0 % 5 return 0?