# 装饰器 # 登录验证 ''' fn是函数本身 fn()函数的调用 装饰器的功能特点 1、不改变原有函数的代码 1、不改变原有函数的调用 3、给函数本身添加一些新的功能 ''' def check(fn): # fn = comment def inner(): print("登录验证") # 发表评论 fn() return inner # 评论函数 def comment(): print("今天天气真好...") if __name__ == '__main__': # comment = check(comment) = inner comment = check(comment) # comment() = check(comment)() = inner() comment()
10-19
4587
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)