“Contoh Dekorator Dasar” Kode Jawaban

# dekorator

# 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

Contoh Dekorator Dasar

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

Jawaban yang mirip dengan “Contoh Dekorator Dasar”

Pertanyaan yang mirip dengan “Contoh Dekorator Dasar”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya