---
# System prepended metadata

title: Decorator
tags: [learning notes, ' Python', ' decorator']

---

---
title: Decorator
tags: learning notes, decorator, Python
---
# Decorator
* 一個函式回傳另一個函式，使用`＠wrapper`語法，被視為函式的轉換，常用的範例是`@classmethod`和`＠staticmethod`
* 裝飾器如其名，下列兩個函式語義定義是相同的：
```python=
def f(...):
    ...
f = staticmethod(f)

@staticmethod
def f(...):
    ...
```