开发者

multiple return statements in python "def" causes syntax error

I'm tryi开发者_如何学编程ng to test my function "def" in a python shell, but when i paste it in there are errors. It seems not to like it when i have multiple return statements inside one "def".

For example:

def foo():
valid = True
if valid:
   return True
return False

Does anyone know why?

thanks!


Your indentation is wrong. Should be this:

def foo():
    valid = True
    if valid:
        return True
    return False
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜