try except else fianlly:
try:
a = 10
b = 20
c = 10
d = (a + b) / c
print(d)
except:
print("There was an exception, except is executed")
else:
print("Because there was no exception, else is executed")
finally:
print("Finally, always executed")
write read file:
my_file = open("firstfile.txt", 'w')
my_file.write(str(item))
my_file.close()
my_file = open("firstfile.txt", 'r')
print(str(my_file.read()))
my_file.close()
With / As:
with open("withas.txt", 'w') as with_as_write:
with_as_write.write(str(item))
with open("withas.txt", 'r') as with_as_read:
print(str(with_as_read.read()))