float.fromhex() From hex string
Last updated: 2026-09-22
float.fromhex() From hex string
float.fromhex(s) converts a hex string to a float (class method).
| Category | Number Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
float.fromhex()
⚙️ Parameters
| s Required | A hexadecimal string, e.g. '0x1.0p0'. |
|---|
Returns:float. The float parsed from the hex string (class method).
Mutates the original:No (returns a new object)
💥 Raises
ValueError— Raised when s is not a valid hexadecimal float string.
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
1.0
0.5
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QIs fromhex() a class method?
AYes; float.fromhex('0x1.0p0') calls it directly and returns 1.0.
QWhat happens with an invalid format?
AA ValueError is raised.
QWhat is the difference from float(s)?
Afloat.fromhex() only parses the hex float format, parsing precisely without loss; float() parses decimal strings.