在python中有一个有趣且非常有用的工具,您可以通过它来模拟函数签名上的元组的值.
def first((a, b)):
return a
x = (4, 9)
first(x)
li = [(5, 4), (8, 9)]
map(first, li)
def second(a, b):
# does not work the same way
return b
Run Code Online (Sandbox Code Playgroud)
我没有看到任何有关此用途的文献.python社区用于此的词汇是什么?有没有令人信服的理由不使用它?
python tuples pattern-matching python-2.7 function-signature