python exception 捕获

你也可以在 except 后面省略异常类型,这表示与任意异常相匹配(包括系统异常等):

node2:/root/python3#cat t9.py 
try:
    s = input('please enter two numbers separated by comma: ')
    num1 = int(s.split(',')[0].strip())
    num2 = int(s.split(',')[1].strip())
    print(num1,num2)
    print(type(num1))
    print(type(num2))
except :
    print('aaaaaaaaaaa')

node2:/root/python3#python3 t9.py 
please enter two numbers separated by comma: a,b
aaaaaaaaaaa

 

你可能感兴趣的:(python,进阶)