简体   繁体   中英

Python: Print nested function return value

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())

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 .)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM