Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Python – Find Functional and Integer Parts – modf() Function with Examples

modf() function is a mathematical function which is use to return the functional and integer parts of x, Their results have the sign of x and are floats.

modf() Function in Python

modf() function exists in Standard math Library of Python Programming Language. The purpose of this function is to returns the integer and fractional parts of x. And they also have same signs as x. The return value of integer part is a float.



The syntax of modf() function in python is:
math.modf( x )



x is any valid Python number (positive or negative).
Note: if the x parameter is not a number, modf() function will return an error.


Return Value

This function will return the fractional and integer part of x which have the same signs as x and also integer part will return a float value.


Python modf() Function Example

Output of Python math.modf() Function
(0.0, 12.0)
(-0.2999999999999998, -2.0)
(-0.0, -5.0)
(-0.0, -75.0)
(0.2999999999999998, 2.0)
(0.5, 3.0)

Note: We need to import math library first and we use this function.


LearnAndLearn.com © 2018 - All rights reserved