Python——lambda匿名函数

匿名函数使用lambda关键字进行定义

定义语法:

lambda 传入参数:函数体(一行代码)

注意事项:
1、lambda匿名函数仅用于构建一个临时函数,只能使用一次,如果要多次使用,需要定义def带名称的函数
2、匿名函数定义中,代码行只能写一行,不允许多行

例:

# 定义一个函数,接受其他函数输入
def test_func(compute):
    result = compute(1,2)
    print(result)

# 通过lambda匿名函数的形式,将匿名函数作为参数传入
test_func(lambda x,y : x-y)

相关推荐

  1. 匿名函数函数

    2023-12-10 11:02:02       32 阅读
  2. Python——lambda匿名函数

    2023-12-10 11:02:02       59 阅读
  3. python之匿名函数

    2023-12-10 11:02:02       33 阅读
  4. 匿名函数lambda

    2023-12-10 11:02:02       38 阅读
  5. 【python】匿名函数

    2023-12-10 11:02:02       29 阅读
  6. MATLAB 匿名函数

    2023-12-10 11:02:02       36 阅读
  7. 匿名函数、lambda匿名函数 ( Everything is up to us!)

    2023-12-10 11:02:02       27 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-10 11:02:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-10 11:02:02       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-10 11:02:02       82 阅读
  4. Python语言-面向对象

    2023-12-10 11:02:02       91 阅读

热门阅读

  1. 第二十九章 控制到 XML 模式的映射 - 类名列表

    2023-12-10 11:02:02       45 阅读
  2. Linux centos7 扩展磁盘

    2023-12-10 11:02:02       49 阅读
  3. vue中的拖拽事件

    2023-12-10 11:02:02       57 阅读
  4. Let和Var的区别

    2023-12-10 11:02:02       55 阅读
  5. 项目记录:跨域问题解决方案

    2023-12-10 11:02:02       58 阅读
  6. js new 原理

    2023-12-10 11:02:02       55 阅读