函数参数中的星号是什么?
当我查看pickle模块时,我看到了这一点:(http://docs.python.org/3.3/library/pickle.html#pickle.dump)
pickle.dump(obj, file, protocol=None, *, fix_imports=True)
Run Code Online (Sandbox Code Playgroud)
我知道在参数之前的单个和双星号(对于可变数量的参数),但这没有任何结果.而且我很确定这与泡菜无关.这可能就是这种情况的一个例子.我把它发送给翻译时我才知道它的名字:
>>> def func(*):
... pass
...
File "<stdin>", line 1
SyntaxError: named arguments must follow bare *
Run Code Online (Sandbox Code Playgroud)
如果重要的话,我在python 3.3.0上.
在浏览源代码时,我注意到 asyncio 库中使用了以下语法:
@coroutine
def sleep(delay, result=None, *, loop=None):
"""Coroutine that completes after a given time (in seconds)."""
if delay == 0:
yield
return result
if loop is None:
loop = events.get_event_loop()
future = loop.create_future()
h = future._loop.call_later(delay,
futures._set_result_unless_cancelled,
future, result)
try:
return (yield from future)
finally:
h.cancel()
Run Code Online (Sandbox Code Playgroud)
什么是*参数列表吗?