0

This does print "None", I want it to print "True", I do not want to alter the last line of the code block.

def outer():
    def inner():
        return True
print(outer())
0

1 Answer 1

4

outer only defines a function, it doesn't call it. If you want outer to return the result of inner, you need to do that:

def outer():
    def inner():
        return True
    return inner()

There is no way to make outer return True without altering it. (Note that you don't have to modify inner.)

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry forgot that inner call, edited my question now. Still same results. Did you test your own code before answering here?
@AchmedDurangi: When I run your updated code, it prints True. Did you test it before asking?
Thanks for verifying, turns out I forgot to add a "return" in front of a recursive call in that construct (not posted above). But your verification helped me solving the problem!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.