Write a python function to count number of times a function is called


Topic: Write a python function to count number of times a function is called

Solution

def counter(fn):
    count = 0
    def inner(*args, **kwargs):
        nonlocal count
        count += 1
        print(f'Function {fn.__name__} was called {count} times.')
        return fn(*"args, **kwargs)    
    return inner



List all Python Programs