Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
220,634 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.