Easy Tutorial
❮ Python Helloworld Ref Math Ldexp ❯

Python3 modf() Function

Python3 Numbers


Description

The modf() method returns the integer and fractional parts of x, both with the same sign as x, and the integer part is represented as a float.


Syntax

Here is the syntax for the modf() method:

import math

math.modf(x)

Note: modf() cannot be accessed directly; it requires importing the math module and calling the method through the static object.


Parameters


Return Value


Example

Below are examples of using the modf() method:

#!/usr/bin/python3
import math  # Import the math module

print("math.modf(100.12) : ", math.modf(100.12))
print("math.modf(100.72) : ", math.modf(100.72))
print("math.modf(119) : ", math.modf(119))
print("math.modf(math.pi) : ", math.modf(math.pi))

The output of the above examples is:

math.modf(100.12) :  (0.12000000000000455, 100.0)
math.modf(100.72) :  (0.7199999999999989, 100.0)
math.modf(119) :  (0.0, 119.0)
math.modf(math.pi) :  (0.14159265358979312, 3.0)

Python3 Numbers

❮ Python Helloworld Ref Math Ldexp ❯