Python 语法错误 except Exception [转]

出这个问题是因为python2和python3 语法有些不同

python2 和 3 处理 except 子句的语法有点不同,需要注意;
Python2

try:
    print ("hello world")
except ZeroDivisionError, err:      # , 加原因参数名称 
    print ('Exception: ', err)

Python3

try:
    print ("hello,world")
except ZeroDivisionError as err:        # as 加原因参数名称
    print ('Exception: ', err)

From:https://blog.csdn.net/DarrenXf/article/details/82957268

猜你喜欢

转载自blog.csdn.net/tony2278/article/details/83512896