saberAMD 发表于 2020-3-22 20:50:13

try语句

请问下try语句是怎么判断底数为1的错误对应的except的,明明后两个except都没有判断语句

zltzlt 发表于 2020-3-22 20:52:10

因为当底数为 1 时 math.log() 会自动抛出 ZeroDivisionError 异常:

>>> import math
>>> math.log(5, 1)
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
    math.log(5, 1)
ZeroDivisionError: float division by zero

saberAMD 发表于 2020-3-22 21:53:34

zltzlt 发表于 2020-3-22 20:52
因为当底数为 1 时 math.log() 会自动抛出 ZeroDivisionError 异常:

感谢
页: [1]
查看完整版本: try语句