DeveloperBreeze

Decorator Development Tutorials, Guides & Insights

Unlock 1+ expert-curated decorator tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your decorator skills on DeveloperBreeze.

Python Decorator to Uppercase Result

Code January 26, 2024
python

# Decorator function to uppercase the result of another function
def uppercase_decorator(function):
    def wrapper(*args, **kwargs):
        result = function(*args, **kwargs)
        return result.upper()
    return wrapper

# Function decorated with the uppercase_decorator
@uppercase_decorator
def greet(name):
    return f'Hello, {name}'

# Usage: Call the decorated function
result = greet('Alice')