Python 异常
1.处理ZeroDivisionError异常
【实例】:
try:
print(5/0)
except ZeroDivisionError:
print("division by zero")
【运行结果】:
division by zero
2.处理FileNotFoundError异常
【实例】:
file = 'da.txt'
try:
with open(file,encoding='utf-8') as f:
contents = f.read()
except FileNotFoundError:
print("File not found")
【运行结果】:
File not found
φ(゜▽゜*)♪ 感谢观看,希望对你有帮助!