繁体   English   中英

在python中什么都不返回意味着什么?

[英]What does return with nothing mean in python?

我正在查看项目的源代码。 在其中我看到了这样的功能。

def func(x):
    if condition_a:
        return
    if condition_b:
        return
    process_something

在这里什么都不做返回什么?

“一无所有的return ”在该行退出函数并返回None 正如Python的文档所说:

如果存在表达式列表,则将对其求值,否则将用None代替。

return使当前函数调用以表达式列表(或None )作为返回值。

在流控制中,我已经看到它通常在遇到某种条件而无法执行其余功能时使用。 例如,

def getDataFromServer():
    if serverNotResponding():
        return
    # do important stuff here which requires the server to be running

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM