Home » Python

math.fmod() method with example in Python

Python math.fmod() method: Here, we are going to learn about the math.fmod() method with example in Python.
Submitted by IncludeHelp, on April 17, 2019

Python math.fmod() method

math.fmod() method is a library method of math module, it is used to find the modulus or given numbers, where the first parameter is a dividend and the second parameter is divisor. It accepts two arguments and returns modulus in float type.

Note: math.fmod() can be used to get the modules/remainder of positive and negative integers, positive and negative floats.

Syntax of math.fmod() method:

    math.fmod(a, b)

Parameter(s): a, b – numbers (positive or negative, integer or float).

Return value: float – it returns a float value, which is a remainder (modulus) of given numbers a, b.

Example:

    Input:
    a = -10
    b = 3

    # function call
    print(math.fmod(a,b))

    Output:
    -1.0

Python code to demonstrate example of math.fmod() method

# Python code to demonstrate example of 
# fmod() method

# importing math
import math

# integer positive numbers
a = 10
b = 3

# calculating modules
result = math.fmod(a,b)
print("result = ", result)

# integer negative numbers
a = -10
b = 3
result = math.fmod(a,b)
print("result = ", result)

# float positive numbers
a = 10.123
b = 3.12
result = math.fmod(a,b)
print("result = ", result)

# float negative numbers
a = -10.123
b = 3.12
result = math.fmod(a,b)
print("result = ", result)

Output

result =  1.0
result =  -1.0
result =  0.762999999999999
result =  -0.762999999999999



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.