Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 7 of 10 · Functions and Lambda Expressions
Interview question

What is a decorator? Decorator क्या है?

Answer
def my_decorator(func):
    def wrapper():
        print('Before')
        func()
        print('After')
    return wrapper

@my_decorator
def say_hello():
    print('Hello!')

say_hello()
# Output:
# Before
# Hello!
# After
@decorator
def func():
    pass

# Function को modify करके return करता है

Was this answer clear?