
Python Cookbook
记录Python Cookbook学习心得
ciky2011
这个作者很懒,什么都没留下…
展开
-
Python Cookbook读书笔记—利用*实现精巧递归
以下为源代码:item = [1, 10, 7, 4, 5, 9]def sum(item): head, *tail = item return head + sum(tail) if tail else headprint(f"sum = {sum(item)}")一下为输出结果:PS C:\Users\zoro.zhang> & C:/Users/zoro.zhang/AppData/Local/Programs/Python/Python39-3原创 2021-02-18 22:53:14 · 240 阅读 · 0 评论 -
*表达式 处理变长元组序列
records = [ ('foo', 1, 2), ('bar', 'Hello'), ('foo', 3, 4)]# records = [# 'foo', 1, 2,# 'bar', 'Hello',# 'foo', 3, 4# ]def do_foo(x, y): print('foo', x, y)def do_bar(s): print('bar', s)for tar, *args in records.原创 2021-02-10 16:51:00 · 415 阅读 · 1 评论