汪汪一只猫
在最后一个语言特性中,区别是很重要的。考虑以下职能:def foo(*positional, **keywords):
print "Positional:", positional print "Keywords:", keywords这个*positional参数将存储传递给foo()没有限制你能提供多少。>>> foo('one', 'two', 'three')Positional: ('one', 'two', 'three')Keywords: {}这个**keywords参数将存储任何关键字参数:>>> foo(a='one', b='two', c='three')Positional: ()Keywords: {'a': 'one', 'c': 'three', 'b': 'two'}当然,您可以同时使用:>>> foo('one','two',c='three',d='four')Positional: ('one', 'two')Keywords: {'c': 'three', 'd': 'four'}这些特性很少被使用,但有时它们非常有用,重要的是要知道哪些参数是位置参数还是关键字。