The remainder method of the math module
The remainder method of the math module returns the remainder of dividing one number by a second. In the first parameter of the method, we specify the number to be divided (the dividend), in the second parameter - the number by which we divide the first (the divisor). Unlike the % operator, the method always returns a real value.
Syntax
import math
math.remainder(dividend, divisor)
Example
Let's find the remainder when dividing the number 25 by 5:
import math
print(math.remainder(25, 5))
Result of code execution:
0.0
Example
Now let's get the remainder of dividing 30 by 4:
import math
print(math.remainder(30, 4))
Result of code execution:
-2.0
Example
Let's find the remainder from dividing the numbers 10 and 3:
import math
print(math.remainder(10, 3))
Result of code execution:
1.0
Example
Now let's try to find out the remainder from dividing the numbers 10 by 0:
import math
print(math.remainder(10, 0))
After executing the code, the function will return us an error:
ValueError: math domain error