Decorators
Decorators are functions that modify the behavior of other functions. They are often used for logging, access control, and more.
def my_decorator(func):
def wrapper():
print("Before the function call")
func()
print("After the function call")
return wrapper
@my_decorator
def say_hello():
print("Hello!")
say_hello()
In this example, my_decorator
wraps the original say_hello
function with additional behavior before and after the function call.