Lesson 30 of 55 · Python
Decorators
Duration: 20 minutes
Lesson 30 of 55 · Python
Duration: 20 minutes
python\ndef debug(func):\n def wrapper(*args, **kwargs):\n print(f'Calling {func.__name__} with args={args}, kwargs={kwargs}')\n result = func(*args, **kwargs)\n print(f'{func.__name__} returned {result}')\n return result\n return wrapper\n\n@debug\ndef add(a, b):\n return a + b\n\nadd(3, 4)\n\n\nThe @debug line is syntactic sugar for add = debug(add).\n