Title: Try, Except, and Finally
Slug: try_except_finally
Summary: Try, Except, and Finally
Date: 2016-05-01 12:00
Category: Python
Tags: Basics
Authors: Chris Albon
In [1]:
# Create some data
scores = [23,453,54,235,74,234]
In [2]:
# Try to:
try:
# Add a list of integers and a string
scores + 'A string of characters.'
# If you get an error, set the error as 'e',
except Exception as e:
# print the error, e
print('Error:', e)
# Then,
finally:
# print end program
print('End Program')
In [3]:
# Try to:
try:
# Print scores
print('Worked!', scores)
# If you get an error, set the error as 'e',
except Exception as e:
# print the error, e
print('Error:', e)
# Then,
finally:
# print end program
print('End program')