Python3 modf() Function
Description
The modf() method returns the integer part and the fractional part of x. Both parts carry the same sign as x, and the integer part is represented as a float.
Syntax
The syntax of the modf() method is as follows:
import math math.modf( x )
Note:modf() cannot be accessed directly. You need to import the math module and call this method via a static object.
Parameters
- x -- A numeric expression.
Return Value
Returns the integer part and the fractional part of x.Example
The following example demonstrates the use of the modf() method:
Example
#!/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))
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))
After running the above example, the output 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)Other Extensions
Python3 Numbers