A ValueError
occurs if you send a string into a function that requires a number:
x = float("hello")
Try it Yourself » Definition and UsageThe ValueError
exception occurs if a function receives a value of wrong type.
You can handle the ValueError
in a try...except
statement, see the example below.
Handling the ValueError
in a try...except
statement:
try:
x = float("hello")
except ValueError:
print("The value has wrong format")
except:
print("Something else went wrong")
Track your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4