Files
Python_CookBook_repo/7.函数/6.定义匿名或内联函数.py
2025-09-10 16:12:45 +08:00

9 lines
302 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 如果我们需要一个短小精悍的函数那么lambda函数是唯一的选择
add = lambda x, y: x + y
print(add(2,3))
# 就比如在sort函数里
names = ["David Beazley", "Brain Jones", "Raymond Hettinger", "Ned Batchelder"]
print(sorted(names, key=lambda name: name.split()[-1].lower()))