Latest web development tutorials

Python3 modf () function

Python3 digital Python3 digital


description

modf () method returns the integer part and the fractional part of x, sign of the value of the two parts with the same x, the integer part in floating-point representation.


grammar

The following is the syntax modf () method:

import math

math.modf( x )

Note: modf () is not directly accessible, you need to import math module, invoke the method through static object.


parameter

  • x - numeric expression.

return value

Returns the integer part and the fractional part of x,

Examples

The following shows an example of using modf () method:

#!/usr/bin/python3
import math   # 导入 math 模块

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 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)

Python3 digital Python3 digital