CKTIS / Python
float()
Converts a numeric input or a valid decimal string into a floating-point number.
Version: Python 3.14; repository image, production runtime not attested
Syntax
float(number=0.0, /)
float(string, /)Converts a numeric input or a valid decimal string into a floating-point number.
A textual exponent is accepted, while a floating-point NaN can be parsed but does not compare equal to itself.
Decimal exponent notation 1.25e2 means 1.25 × 100, producing the float 125.0. The parser also accepts nan; this special float is unequal to itself. Ordinary nonnumeric text raises ValueError. Calling with no argument yields 0.0.
assert float() == 0.0 and float("1.25e2") == 125.0
x = float("nan")
assert x != x
Examples
print(float("1.25e2"))
x = float("nan")
print(x == x)
Result
125.0 False
Decimal exponent notation 1.25e2 means 1.25 × 100, producing the float 125.0. The parser also accepts nan; this special float is unequal to itself. Ordinary nonnumeric text raises ValueError. Calling with no argument yields 0.0.