How do I use decorators

Learn how to utilize decorators in Python, a powerful feature that allows you to modify the behavior of functions or methods. This guide includes a practical example to illustrate how decorators can enhance your code functionality.
decorators, Python, programming, functions, methods, code enhancement, examples

def my_decorator(func):
    def wrapper():
        print("Something is happening before the function is called.")
        func()
        print("Something is happening after the function is called.")
    return wrapper

@my_decorator
def say_hello():
    print("Hello!")

say_hello()
    

decorators Python programming functions methods code enhancement examples