decorator pattern fibprev fib for num in range( )fibprevfib fibfib fibprev return fib if __name__ ="__main__" print("fibonacci number for {}{}format(nfib( ))as beforewhen the compiler reaches the \@profiling_decorator_with_unit it calls the functionwhich returns the decoratorwhich is then applied to the function being decorated you should also note that once again we used the closure concept to handle parameters passed to the decorator decorating classes if we wanted to profile every method call in specific classour code would look something like thisclass domathstuff(object)@profiling_decorator def fib(self)@profiling_decorator def factorial(self)applying the same method to each method in the class would work perfectly finebut it violates the dry principle (don' repeat yourself what would happen if we decided we were happy with the performance and needed to take the profiling code out of number of sprawling classeswhat if we added methods to the class and forgot to decorate these newly added methodsthere has to be better wayand there is what we want to be able to do is decorate the class and have python know to apply the decoration to each method in the class