Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python math.fmod() Method

Python math.fmod() Method

Python math Module Python math Module

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:

**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

print

(

math

.

fmod

(

20

,

4

)

)

print

(

math

.

fmod

(

20

,

3

)

)

print

(

math

.

fmod

(

15

,

6

)

)

print

(

math

.

fmod

(

10

,

3

)

)

Raises an error, ValueError: math domain error

print

(

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 Python math Module