Python Function Reference

float

Convert a number or a string to a floating-point number.

Python 3.13
float([x])
  • [ ]optional part
x
A number or a string with a number, such as "3.14", "1e3" or "inf".
int | float | strOptional

Return value

A float; 0.0 without arguments. Raises ValueError for an invalid string.

Examples

Float from a string

Python 3.13
print(float('3.14'))
3.14

Scientific notation

Python 3.13
print(float('1e3'))
1000.0

Details

The decimal separator in a string must be a point: float("3,14") raises ValueError.

See also

Where to learn