Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python modf() function

Python modf() function

Python Numbers Python Numbers


Description

The modf() method returns the integer and fractional parts of x, both with the same sign as x; 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 the method through the static object.


Parameters


Return Value

Returns the integer and fractional parts of x,


Example

The following shows examples of using the modf() method:


#!/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)

Running the example above produces:


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)

Python Numbers Python Numbers