Python math.remainder() Method
Python mathremainder(x, y)The method returns the remainder of x/y.
Python version: 3.7
Syntax
The syntax of the math.remainder() method is as follows:
math.remainder(x, y)
Parameter description:
- x-- Required, the dividend.
- y-- Optional, the divisor. Must be a non-zero number, otherwise a ValueError will occur.
Return value
A floating-point value, returns the remainder.
Example
The following example calculates the remainder:
Example
# Import the math package
import math
# remainder of x/y
print (math.remainder(9, 2))
print (math.remainder(9, 3))
print (math.remainder(18, 4))
print (math.remainder(23.5, 5))
print (math.remainder(23, 5.5))
print (math.remainder(12.5, 2.5))
print (math.remainder(12, 2))
import math
# remainder of x/y
print (math.remainder(9, 2))
print (math.remainder(9, 3))
print (math.remainder(18, 4))
print (math.remainder(23.5, 5))
print (math.remainder(23, 5.5))
print (math.remainder(12.5, 2.5))
print (math.remainder(12, 2))
Output result:
1.0 0.0 2.0 -1.5 1.0 0.0 0.0Other extensions
Python math Module