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
| Name | Type | Description |
|---|---|---|
| number | number or conversion-protocol object | Numeric form; defaults to 0.0. |
| string | str or supported bytes-like input | Decimal 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))