CKTIS / Python
float()
Erzeugt eine Gleitkommazahl aus einer Zahl oder Zeichenkette.
Version: Python 3.14; repository image, production runtime not attested
Syntax
float(number=0.0, /)
float(string, /)Erzeugt eine Gleitkommazahl aus einer Zahl oder Zeichenkette.
1.25e2 bedeutet 1,25 · 100 und ergibt 125,0. Die spezielle Schreibweise nan ist gültig, das Ergebnis ist sich jedoch nicht gleich. Ungültiger Text löst ValueError aus.
Ohne Argument folgt 0,0.
assert float() == 0.0 and float("1.25e2") == 125.0
x = float("nan")
assert x != x
Beispiele
print(float("1.25e2"))
x = float("nan")
print(x == x)
Ergebnis
125.0 False
Ohne Argument folgt 0,0.