IT评测·应用市场-qidao123.com技术社区
标题:
Python语法系列博客 · 第9期[特别字符] 函数参数进阶:*args、**kwargs 与参数解包技巧
[打印本页]
作者:
悠扬随风
时间:
7 天前
标题:
Python语法系列博客 · 第9期[特别字符] 函数参数进阶:*args、**kwargs 与参数解包技巧
上一期小练习解答(第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
复制代码
本期主题:函数参数进阶
欢迎光临 IT评测·应用市场-qidao123.com技术社区 (https://dis.qidao123.com/)
Powered by Discuz! X3.4