lhl
首页
python
leetcode
产品思想
软件测试
博客 (opens new window)
github (opens new window)
首页
python
leetcode
产品思想
软件测试
博客 (opens new window)
github (opens new window)
  • python

    • Python 基础

    • Python 数据库

    • 面向对象

    • Python Web

    • Python 进阶

      • 协程
      • 装饰器
      • decorator
      • filter
      • 列表生成式
      • 进程&线程
      • 生成器
      • 匿名函数
        • 匿名函数
      • map&&reduce
      • venv
  • leetcode

  • 软件测试

  • Git

  • linux

  • 产品

  • MySql

  • docker

  • python
  • 进阶
2023-07-16
目录

匿名函数

# 匿名函数

# 简单使用

lambda x: x * x
## 相当于
def func(x):
    return x * x

x: x*x, :前是函数参数, x*x 是函数返回值

## 
import math


def c1(r):
    return math.pi * r * r


print(c1(3))
print(c1(5))

c2 = lambda r: math.pi * r * r
print(c2(3))
print(c2(5))

# 小测试

## https://www.liaoxuefeng.com/wiki/1016959663602400/1017451447842528
## def is_odd(n):
##     return n % 2 == 1
is_odd = lambda n: n % 2 == 1
L = list(filter(is_odd, range(1, 20)))
生成器
map&&reduce

← 生成器 map&&reduce→

最近更新
01
lhl learn notes
02
filter
06-09
03
decorator
06-09
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式