Python Exception draft

Last modified 2 years ago / Edit on Github
Warning
This post was updated more than 1 year ago, some information may be outdated!
Warning
This is a draft, the content is not complete and of poor quality!

Try..Except

try:
# codes
except:
# codes run if there is an exception
try:
# codes
except:
# codes run if there is an exception
else:
# no exception?
try:
# try codes
except FileNotFoundError as fnf_error:
print(fnf_error)
except AssertionError as error:
print(error)

Other Errors, check this list.

Apply

Check str of float

element = 'mean'
try:
print(float(element))
except ValueError:
if element == 'mean':
print('hello mean')