马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
上一期小练习解答(第8期回顾)
✅ 练习1:整数转字符串列表
- nums = [1, 2, 3, 4, 5]
- str_list = list(map(str, nums))
复制代码 ✅ 练习2:筛选回文字符串
- words = ["madam", "hello", "noon", "python"]
- palindromes = list(filter(lambda x: x == x[::-1], words))
复制代码 ✅ 练习3:使用 reduce 计算乘积
- from functools import reduce
- product = reduce(lambda x, y: x * y, [2, 3, 4]) # 24
复制代码 ✅ 练习4:lambda 表达式计算 x² + 2x + 1
- quad = lambda x: x**2 + 2*x + 1
- result = quad(3) # 16
复制代码 本期主题:函数参数进阶
|