math.modf(x) splits x into two parts and returns the tuple (fractional_part, integer_part), where both elements are floats carrying the sign of x.
For example, math.modf(-3.75) returns (-0.75, -3.0). Notice the fractional part comes first and the whole part second.
math.modf() is a function in Python's standard math module: import it with import math and call math.modf(...), or import the name directly with from math import modf.
Syntax
Import math and unpack the two-float tuple.
python
import math
frac_part, int_part = math.modf(x)
Call
What it does
math.modf(3.75)
Returns (0.75, 3.0).
math.modf(-3.75)
Returns (-0.75, -3.0) (both parts keep negative sign).
math.modf(float("inf"))
Returns (0.0, inf).
math.modf(-0.0)
Returns (-0.0, -0.0).
Both elements are floats (not ints); if you only need an integer whole part, call math.trunc().
Function signatures
python
math.modf(x, /)
# returns: (frac, whole) tuple of two floats with the sign of x
Parameters
Parameter
Description
x
Required positional number (int or float).
Return Value
Return Value
Description
tuple
A 2-tuple (fractional_part, integer_part) of two floats.
Python Examples
Example 1 — Split Positive and Negative Floats Into Fraction and Whole
Unpack math.modf() across mixed values and inspect negative fractional signs.
python
import math
for val in [3.75, -3.75, 5.0, -0.25]:
frac, whole = math.modf(val)
print(f"{val:>5} -> frac={frac}, whole={whole}")