Python math.fmod() Method
Python math.fmod(x, y) The method returns the remainder of x/y.
Python version: 2.7
Syntax
The syntax of the math.fmod() method is as follows:
math.fmod(x, y)
Parameter Description:
- x -- required, a positive or negative number. The dividend. If x is not a number, a TypeError is returned.
- y -- required, a positive or negative number. The divisor. If y is not a number, a TypeError is returned.
**Note:** if x and y = 0, a ValueError is returned.
**Note:** if y = 0, a ValueError is returned.
**Note:** if x or y is not a number, a TypeError is returned.
Return Value
A floating-point value representing the remainder of x/y
Example
The following example computes the remainder:
Example
Import the math package
import
math
Compute the remainder
(
math
.
fmod
(
20
,
4
)
)
(
math
.
fmod
(
20
,
3
)
)
(
math
.
fmod
(
15
,
6
)
)
(
math
.
fmod
(
10
,
3
)
)
Raises an error, ValueError: math domain error
(
math
.
fmod
(
0
,
0
)
)
Output result:
0.0
2.0
3.0
-1.0
Traceback (most recent call last):
File "/Users/RUNOOB/runoob-test/test.py", line 9, in
print(math.fmod(0, 0))
ValueError: math domain error
Python math Module