Home › Python Tutorial › Python try...except, None and input
Python try...except, None and input
Handle errors and missing values.
Put risky code in try and handle errors in except. else runs if nothing failed and finally always runs. None means no value; test it with is None. input() reads what the user types (not available in this page).
Commands in this lesson
input
Definition: Form control where the user types or chooses a value.
Syntax:
<input type="text" name="n">
Example:
<input type="text" placeholder="Your name">Example code
try:
n = int("abc")
except ValueError:
print("Not a number")
else:
print("ok")
finally:
print("done")
x = None
print(x is None)