I am trying to return the function with arguments and the functions results in the format of the print statement. The code works except I am getting a "None" between each answer when a test is run. How do I prevent the None from printing?
def debug(func):
"""
:param func: function
"""
def inner_func(*args,**kwargs):
answer = func(*args,**kwargs)
return print(f"{func.__name__}{args} was called and returned {answer}")
return inner_func
And the test:
def add(a, b):
return a + b
@debug
def sub(a, b=100):
return a - b
print(add(3, 4))
print(sub(3))`
print(sub(3,4))
add(3, 4) was called and returned 7
None
sub(3,) was called and returned -97
None
sub(3, 4) was called and returned -1
None
Expected Output:
add(3, 4) was called and returned 7
sub(3) was called and returned -97
sub(3, 4) was called and returned -1