Built-in Functions and Types

float()

Create a floating-point value from a number or decimal text, including scientific notation. Text may also denote infinity or NaN. Conversion can round values that cannot be represented exactly; it is not exact decimal arithmetic. Invalid numeric text raises ValueError, and integer conversion beyond the floating-point range can raise OverflowError. Objects may provide __float__() or __index__().

Formal Syntax & Structure

python syntaxpython
float(number=0.0, /)float(string, /)

Parameters & Attributes

NameTypeDescription
numbernumber or conversion-protocol objectNumeric form; defaults to 0.0.
stringstr or supported bytes-like inputDecimal text form, instead of number.

Return Value

float

Floating-point representation of the input.

Working Example

Example Snippetpython
print(float("3.125e1"))print(float(7))
Python Reference