How to find the fractional and integer parts of x in a two-item tuple in Python?


The method modf() returns the fractional and integer parts of x in a two-item tuple. Both parts have the same sign as x. The integer part is returned as a float. First item in tuple is fractional part

>>> import math
>>> math.modf(100.73)
(0.730000000000004, 100.0)
>>> math.modf(-5.55)
(-0.5499999999999998, -5.0)


Updated on: 02-Mar-2020

97 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements