Python Tutorial Python Advanced Python Resources Python Libraries
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

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

5