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

PythonServer Side ProgrammingProgramming

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)


raja
Updated on 02-Mar-2020 10:16:43

Advertisements