可以编写如下代码来捕获异常
a, b=5, 0 try: if b != 0: print a/b else: a/b raise ZeroDivisionError except Exception as e: print e
我们得到以下输出
C:/Users/nhooo1/~.py integer division or modulo by zero