开发者

multiple return statements in python "def" causes syntax error

开发者 https://www.devze.com 2023-01-22 23:57 出处:网络
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\".

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

精彩评论

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