python Python:尝试,除了ZeroDivisionError,TypeError

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Python:尝试,除了ZeroDivisionError,TypeError相关的知识,希望对你有一定的参考价值。

def division_try(anumber):
    try:
        return 100 / anumber
    except ZeroDivisionError:
        return "Sorry, Python does NOT divide by zero."

print(division_try(0))        # exception: ZeroDivisionError
print(division_try(50.0))     # 2.0
print(division_try("hello"))  # exception: TypeError

以上是关于python Python:尝试,除了ZeroDivisionError,TypeError的主要内容,如果未能解决你的问题,请参考以下文章