博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python | Lambda函数与示例
阅读量:2529 次
发布时间:2019-05-11

本文共 732 字,大约阅读时间需要 2 分钟。

With the help of lambda function, we can create one line function definition.

借助lambda函数,我们可以创建一个行函数定义。

Note: Function must have return type and parameter

注意:函数必须具有返回类型和参数

Example:

例:

Convert temperature from Celsius to Fahrenheit

将温度从摄氏温度转换为华氏温度

1) Approach 1: Using normal way

1)方法1:使用常规方法

# function definition to convert from c to Fdef ctof(c):    f=9/5*c+32    return f# input c=int(input("Enter Temp(C): "))# function callf=ctof(c)# print print("Temp(F) :",f)

Output

输出量

Enter Temp(C): 10Temp(F) : 50.0

2) Approach 2: Using lambda

2)方法2:使用lambda

# lambda function ctof = lambda c:9/5*c+32# input c=int(input("Enter Temp(C):"))# function callf=ctof(c)# print print("Temp(F) :",f)

Output

输出量

Enter Temp(C): 10Temp(F) : 50.0

翻译自:

转载地址:http://uttzd.baihongyu.com/

你可能感兴趣的文章
搜索框键盘抬起事件2
查看>>
阿里百川SDK初始化失败 错误码是203
查看>>
透析Java本质-谁创建了对象,this是什么
查看>>
BFS和DFS的java实现
查看>>
QQ是怎样实现好友桌面快捷方式的?
查看>>
hadoop之安装
查看>>
Xamarin.Android开发实践(六)
查看>>
物联网项目的思考
查看>>
IntelliJ IDEA设置不自动打开最后关闭的项目
查看>>
抽象类
查看>>
ARC 101E.Ribbons on Tree(容斥 DP 树形背包)
查看>>
List数据分页
查看>>
kmp总结
查看>>
vuex模块相互调用
查看>>
js数字格式化千分位格式
查看>>
windows pip 安装 whl文件
查看>>
Java——常用类(String)
查看>>
Map容器
查看>>
tomcat查看线程数
查看>>
SpringMVC源码阅读:定位Controller
查看>>