What does the following code output? from functools import wraps def debug(func): @wraps(func) def wrapper(*args, **kwargs): return func(*args, **kwargs) return wrapper @debug def greet(name): ”’Says hello”’ return f’Hello {name}’ print(greet.__name__, greet.__doc__)

Python Professional Hard

Python Professional — Hard

What does the following code output? from functools import wraps def debug(func): @wraps(func) def wrapper(*args, **kwargs): return func(*args, **kwargs) return wrapper @debug def greet(name): ”’Says hello”’ return f’Hello {name}’ print(greet.__name__, greet.__doc__)

Key points

  • Decorators like @wraps can maintain original function metadata
  • The wrapper function acts as a middleman between the decorator and the original function
  • The __name__ attribute holds the function name
  • The __doc__ attribute holds the function docstring

Ready to go further?

Related questions