Introduction to the modf () method in Python
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
The modf () method 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:
?
|
1
2
3 |
Import math
Math. 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.
?
|
1
2
3
4
5
6
7 |
#! /Usr/bin/python
Import math # This will import math module
Print "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:
?
|
1
2
3
4 |
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)
|