float() Float constructor
Last updated: 2026-09-22
float() Float constructor
float() converts a string or number to float; with no args returns 0.0.
| Category | Built-in Functions |
|---|---|
| Kind | Built-in Function |
| Python Version | all |
📝 Syntax
float([x])
⚙️ Parameters
| x Optional | A string or number; omitted yields 0.0.(Default:None) |
|---|
Returns:float. The converted floating-point number.
💥 Raises
ValueError— Raised when a string cannot be parsed as a float.TypeError— Raised when x's type cannot be converted to float.
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
3.14
5.0
0.0
🏷️ Related Built-in Functions
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat happens with float('abc')?
AIt raises ValueError: could not convert string to float: 'abc'; the string must parse as a number.
QAre float('nan') and float('inf') valid?
AYes, they return nan (not-a-number) and inf (infinity) respectively; Python floats support both special values.
QHow does float() conversion differ from int()?
Afloat(3) gives 3.0 (turning a number into float); int(3.99) gives 3 because int() truncates toward zero on floats rather than rounding.
QWhat does float() return with no arguments?
AIt returns 0.0.