记录学习python时的问题(一)
2018-01-24 23:41
369 查看
看python官方文档时看到
lambda expression
Small anonymous functions can be created with the
function returns the sum of its two arguments:
Lambda functions can be used wherever function objects are required. They are syntactically restricted to a single expression. Semantically, they are just syntactic sugar for a normal function definition. Like nested function definitions, lambda functions
can reference variables from the containing scope:
这个例子看不懂,故在解释器中运行了 make_incrementor(42) 结果发现这是个函数,于是恍然大悟,原来
lambda expression
Small anonymous functions can be created with the
lambdakeyword. This
function returns the sum of its two arguments:
lambda a, b: a+b.
Lambda functions can be used wherever function objects are required. They are syntactically restricted to a single expression. Semantically, they are just syntactic sugar for a normal function definition. Like nested function definitions, lambda functions
can reference variables from the containing scope:
>>> def make_incrementor(n): ... return lambda x: x + n ... >>> f = make_incrementor(42) >>> f(0) 42 >>> f(1) 43
这个例子看不懂,故在解释器中运行了 make_incrementor(42) 结果发现这是个函数,于是恍然大悟,原来
return lambda x: x + n
返回一个匿名函数,x是传入的参数,x + n 是返回值
相关文章推荐
- Python字符编码问题-学习记录
- 记录学习python时的问题(二)
- 既然决定学习python就开始记录一些问题吧
- Python学习问题记录
- 【Python3.6爬虫学习记录】(七)使用Selenium+ChromeDriver爬取知乎某问题的回答
- Python 学习记录(1)对象命名导致的问题
- python3学习记录——安装pyspider中lxml安装问题
- Python 学习问题记录
- python django学习-问题记录及解决方法
- python学习问题记录
- python3学习记录——安装pyspider中lxml安装问题
- 学习python过程遇到的问题与记录
- 记录Python学习中的几个小问题
- Ubuntu中python环境下import requests错误的解决(学习过程问题记录)
- 学习Python 是遇到的一些问题记录
- django学习记录,动态url,另外发现django的时区问题
- [项目过程中所遇到的各种问题记录]学习篇——对工作以来的学习过的开源项目进行总结—DiscuzNt
- python学习记录
- [项目过程中所遇到的各种问题记录]学习篇——对工作以来的学习过的开源项目进行总结—动软代码生成工具
- Python模块学习 ---- logging 日志记录(一)