This article describes how to use the modf () method to get started with Python. It is a basic knowledge of Python learning. For more information, see modf () returns the integer decimal part of the tuples x of two items. These two tuples have the same x symbol. Returns the integer part of a floating point number.
Syntax
The syntax of the modf () method is as follows:
import mathmath.modf( x )
Note: This function cannot be directly accessed. Therefore, we need to import the math module and then use the static object of math to call this function.
Parameters
- X -- this is a numeric expression.
Return Value
This method returns the integer decimal part of x in the tuples of the two items. Has the same x symbol. Returns a floating point number.
Example
The following example shows how to use the modf () method.
#!/usr/bin/pythonimport math # This will import math moduleprint "math.modf(100.12) : ", math.modf(100.12)print "math.modf(100.72) : ", math.modf(100.72)print "math.modf(119L) : ", math.modf(119L)print "math.modf(math.pi) : ", math.modf(math.pi)
When we run the above program, it will produce the following results:
math.modf(100.12) : (0.12000000000000455, 100.0)math.modf(100.72) : (0.71999999999999886, 100.0)math.modf(119L) : (0.0, 119.0)math.modf(math.pi) : (0.14159265358979312, 3.0)