Python Tutorial Python Advanced Python References Python Libraries

Python math - fmod() Function



The Python math.fmod() function is used to compute the remainder operation (modulo) on two arguments.

Syntax

math.fmod(x, y)   

Parameters

x Required. Specify the dividend.
y Required. Specify the divisor.

Return Value

Returns the remainder (modulo) when x is divided by y.

Exceptions

  • Throws ValueError, if both x and y are 0.
  • Throws ValueError, if y is 0.
  • Throws TypeError, if x or y is not a number (NaN).

Example:

In the example below, fmod() function is used to calculate the modulo of given arguments.

import math

print(math.fmod(10, 4))
print(math.fmod(14, 4))
print(math.fmod(60.8, 18.1))

The output of the above code will be:

2.0
2.0
6.499999999999993

❮ Python Math Module