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

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.