'return' outside function


def shut_down(s):
return s
if s=='yes':
return "Shutting down"
elif s=='no':
return "Shutdown aborted"
return "Sorry"

I don't know which part is wrong. Every time I submit, it shows:
File "python", line 4
SyntaxError: 'return' outside function

Please help me. Thanks!


return s
This is creating an errror!

meaning of return...
When a function hits return then it simply says "lets halt our execution and get off from function's body"

Thats why your other statements(inside the function) are not getting executed!


Also.. Properly indent your code..

for example..

def exampe():
    if some_condition:
        return something


SyntaxError: 'return' outside function

return only makes sense inside the function.

may be you've done something like

def shut_down(s):
    return s
if s=='yes':
    return "Shutting down"

so right now if..else is not part of the shut_down function.so you are getting that error.

also you don't need to use the return s statement as @greentreemee said the meaning of return and see the example too.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.