Python - math.remainder() Function
The Python math.remainder() function is used to compute the remainder operation on two arguments. The remainder can be expressed as follows:
Remainder = x - y * Q, where Q is the quotient of x/y rounded to the nearest integer. If x/y falls exactly at the midway between two integers, the even integer is returned.
In special cases it returns the following:
- If x - y * Q is zero, the method returns +0 if x is positive and -0 if x is negative.
#New in version 3.7 math.remainder(x, y)
Returns the remainder when x is divided by y.
In the below example, remainder() function is used to calculate the remainder operation on two given arguments.
import math print(math.remainder(10, 4)) print(math.remainder(14, 4)) print(math.remainder(60.8, 18.1))
The output of the above code will be:
2.0 -2.0 6.499999999999993
❮ Python Math Module