pyclass-修飾器 發表於 2023-11-13 更新於 2023-12-14 分類於 人生苦短,我學Python 閱讀次數: 6 文章字數: 74 所需閱讀時間 ≈ 1 分鐘 使用@property將method變成物件變數 1234567891011121314class train: def __init__(self) -> None: self._tempArem = 0 @property def temp(self): return self._tempArem + 30test = train()print(test._tempArem)print(test.temp)# 0# 30 如何自製裝飾器12345678910111213def test(func): x = 50 print(x) return func@testdef foo(): print(100)foo()# 50# 100 上述為最簡易的裝飾器 作者: xiaLotus 文章連結: https://xialotus.github.io/2023/11/13/pyclass-修飾器/ 版權聲明: 本網誌所有文章除特別聲明外,均採用 BY-NC-SA 許可協議。轉載請註明出處!