“Basic Decorator Beispiel” Code-Antworten

# Dekorateur

# decorator function
def outer(func):
    def inner():
        str1 = func() 
        return str1.upper() # addition of functionality
    return inner

@outer 
def print_str():
    return "good morning"

print(print_str())

# Output -> 'GOOD MORNING'
# A decorator is a function that takes another function as an argument, adds some kind of functionality to it and returns another function. Python decorators help add functionality to an existing code(function) which may aid in code reusability. 
Impossible Impala

Basic Decorator Beispiel

def log_result(func):
  def inner():
    res = func()
    print(res)
    return res
Json Bourne

Ähnliche Antworten wie “Basic Decorator Beispiel”

Fragen ähnlich wie “Basic Decorator Beispiel”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen