简单 Python 问:我知道执行此代码时会产生什么 None

Simple Python Q: idk what produces None when this code's executed

我只是通过阅读一本书来学习 Python,下面的代码用于显示 try 和 except 命令。这些是有道理的,但我的问题是关于输出。执行时,sp​​am(0) 出错后,在下一行显示 None,然后是 42。None 来自哪里?

def spam(divideBy):
    try:
        return 42 / divideBy
    except ZeroDivisionError:
        print('Error')

print(spam(2))
print(spam(12))
print(spam(0))
print(spam(1))

在 Python 中,没有 return 语句的函数 return None。于是异常被捕获,函数returns,然后下一行执行。

如果 except 块再次引发异常,则该函数不会 return,而是会抛出异常。