Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Python Fundamentals

Lesson 30 of 55 · Python

Decorators

Duration: 20 minutes

Decorators\n\nA decorator is a higher‑order function that wraps another function to extend its behavior without modifying the original code.\n\npython\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

Previous: Magic Methods and DunderNext: Generators and Iterators