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
pythonimport math
math.remainder(dividend, divisor)
Example
Let's find the remainder when dividing the number 25 by 5:
pythonimport math
print(math.remainder(25, 5))
Result of code execution:
python0.0
Example
Now let's get the remainder of dividing 30 by 4:
pythonimport math
print(math.remainder(30, 4))
Result of code execution:
python-2.0
Example
Let's find the remainder from dividing the numbers 10 and 3:
pythonimport math
print(math.remainder(10, 3))
Result of code execution:
python1.0
Example
Now let's try to find out the remainder from dividing the numbers 10 by 0:
pythonimport math
print(math.remainder(10, 0))
After executing the code, the function will return us an error:
errorValueError: math domain error