*在C中具有特殊含义,就像在C中一样吗?我在Python Cookbook中看到了这样的函数:
def get(self, *a, **kw)
Run Code Online (Sandbox Code Playgroud)
您能否向我解释或指出我能在哪里找到答案(Google将*解释为外卡字符,因此我找不到满意的答案).
非常感谢你.
究竟是什么*args和**kwargs意味着什么呢?
根据Python文档,从它看来,它传递了一个参数元组.
def foo(hello, *args):
print hello
for each in args:
print each
if __name__ == '__main__':
foo("LOVE", ["lol", "lololol"])
Run Code Online (Sandbox Code Playgroud)
打印出:
LOVE
['lol', 'lololol']
Run Code Online (Sandbox Code Playgroud)
你如何有效地使用它们?
python ×2