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
精彩评论