#匿名函数的特点
#1,匿名函数也是函数,调用时需要加上括号
#2,匿名函数只能有一行代码
#3,匿名函数的返回值不用return关键字
# lambda 参数1,参数2:返回的表达式
# 匿名函数作为参数给其他函数使用,简化代码

# 变量new_func是函数
new_func = lambda x, y:x + y
result = new_func(1, 2)
print(result)

匿名函数作为参数给其他函数使用,
主要配合高阶函数使用
# 定义无参数的匿名函数,输入‘hello world’
# func = lambda: print('hello world')
# func()


def sum_num(num1, num2):
return num1 + num2
def show(func):
    print('sum_num函数还未执行!')
    a = 1
    b = 2
    result = func(a, b)
    print(result)
    print('sum_num函数执行了')
View Code

相关文章:

  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2021-06-22
  • 2021-10-29
猜你喜欢
  • 2022-12-23
  • 2023-03-31
  • 2022-12-23
  • 2021-12-17
  • 2021-09-25
  • 2022-12-23
相关资源
相似解决方案