python异常

#:异常处理! 
try 语句可以跟else语句

基本用法
try: 语局
except BaseException#代表所有异常:语句
else:语句
while True:

try:
num1 = input('输入被除数:')
num2 = input('输入除数:')
result = int(num1) / int(num2)
except BaseException: #异常的基类,代表所有异常
print('错误输入!')
except ZeroDivisionError: #
print('0不能作为除数'+' ')
except ValueError: #字母空置类异常
print('请勿输入空值或字母'+' ')
else:
print('运算结果为:%d'%result+' ')
原文地址:https://www.cnblogs.com/lc1013/p/10211584.html