在python中什么都没有意义?

时间:2014-04-22 02:30:45

标签: python

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

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

这回事什么都没有?

1 个答案:

答案 0 :(得分:6)

" return没有任何内容"退出该行的函数并返回None。正如Python's docs所说:

  

如果存在表达式列表,则对其进行评估,否则替换None

     

return将当前函数调用与表达式列表(或None)一起作为返回值。

在流量控制中,我已经看到它在遇到某种条件时常用,这使得无法执行其余的功能;例如,

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