python学习-装饰器
来源:互联网 发布:php大牛的博客 编辑:程序博客网 时间:2024/06/16 14:33
def outer(func): def inner(): print("begin") func() return inner@outerdef f1(): print("hello")f1()--------------运行结果-------------beginhello
“@outer”功能:
- 自动执行outer函数,并将下面的函数名称f1当做参数传递给outer函数
- 执行f1时,实际上会自动去执行outer函数,并且此时的参数func即f1
- 将outer函数的返回值,重新赋值给f1
- outer函数的返回值为inner(为函数,非inner(),inner()对应的是执行print与f1(),对应的返回值为None),因此f1被赋值为inner。f1()即对应inner()。
0 0
- Python装饰器学习
- Python装饰器学习
- Python装饰器学习
- Python装饰器学习
- python 装饰器学习
- Python装饰器学习
- python 装饰器学习
- Python装饰器学习
- Python装饰器学习
- Python装饰器学习
- python装饰器学习
- Python装饰器学习
- python学习-装饰器
- Python装饰器学习
- Python装饰器学习
- python 装饰器学习
- Python装饰器学习
- Python装饰器学习
- Redis SDS
- Camera基本开发知识
- NO.7 HTML之继续列表之旅
- C#中的ToolStrip控件的使用
- 配置BaseApplication,方便项目中随时调用上下文Context
- python学习-装饰器
- 找出数组中超出总数1/4的数字
- 如何安装MySQL5.0图解教程
- Android6.0指纹识别开发实例
- Android相关
- Hbase 学习总结
- PAT B1049
- static,const以及extern的区别
- [JZOJ 4855]荷花池塘