Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Returning function call vs just calling the function

I am taking the python functional programming course. In the functions.py file there is a function as follows . . .

def log_and_run(func):
    print("I just got {}".format(func.__name__))
    return func()

I would like to know the difference in returning a function call at the end of a function, and just calling the function like below . .

def log_and_run(func):
    print("I just got {}".format(func.__name__))
    func()

1 Answer

Steven Parker
Steven Parker
230,274 Points

In both examples the function "func" will run, but in the first example any value returned by "func" will then also be returned by "log_and_run" to the code that called it.

In the second example, "log_and_run" does not return any value, and anything that "func" might have returned is lost.

Okay I see now thanks! It was not clear in the example from the video because the function used did not have a return value.