Um einen Text in ein Float umzuwandeln, will ich sicherstellen, dass bevor ich es umwandel, der String auch wirklich in ein Float umgewandelt werden kann.
Also mache ich:
Code: Alles auswählen
>>> x = "1212.56"
>>> isinstance(float(x),float)
True
Code: Alles auswählen
>>> isinstance(float("Hallo"),float)
Traceback (most recent call last):
File "<pyshell#2>", line 1, in -toplevel-
isinstance(float("Hallo"),float)
ValueError: invalid literal for float(): Hallo