DeveloperBreeze

Python Decorator to Uppercase Result

# 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')

Continue Reading

Handpicked posts just for you — based on your current read.

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!