Py学习  »  Chends  »  全部回复
回复总数  1
8 年前
回复了 Chends 创建的主题 » python函数不返回任何内容

我测试了你的功能,正如其他人所说,如果你想打印一些东西,一定要在返回之前打印出来。因为什么 返回 Do只是返回输出并退出函数调用(我的意思是:下面什么都没有 返回 将运行)。您可以执行如下操作来测试代码:

def test(a):
    if a:
        return True
    return False

a = None
if test(a):
    print("True, input is not null")
else:
    print("False, input is null!")

返回:

False, input is null!