I think there is no direct or โeasyโ way to do this. However, one way would be to define a decorator that prints this. For instance:
import random def print_return(func): def func_wrapper(param): rv = func(param) print("Return value: {0}".format(rv)) return rv return func_wrapper @print_return def secret_number(secret_number_range): return random.randrange(1, secret_number_range + 1)
source share