YuNing's Thought

Home

❯

Notes

❯

Python Decorator

Python Decorator

Nov 05, 20231 min read

Decorator

A function returning another function, usually applied as a function transformation using the @wrapper syntax. Common examples for decorators are classmethod() and staticmethod().

It was inspired in part by Java annotations, and have a similar syntax; the decorator syntax is pure syntactic sugar, using @ as the keyword:

def make_pretty(func):
    def inner():
        print("I got decorated")
        func()
    return inner

Links

  • Python Docs
  • Python syntax and semantics - Wikipedia

Graph View

  • Decorator
  • Links

Backlinks

  • Decorator Pattern
  • Python

Created with Quartz v4.5.2 © 2025

  • GitHub
  • Discord Community