<分区>
以下代码中的*
是什么意思(在pprint
库中找到)?
def pformat(object, indent=1, width=80, depth=None, *, compact=False):
"""Format a Python object into a pretty-printed representation."""
return PrettyPrinter(indent=indent, width=width, depth=depth,
compact=compact).pformat(object)
如果它是 *args
那么它将是任意数量的位置参数。参数值将在名为 args
的元组中。前 4 个参数可以按名称或位置分配,参数 compact
只能按名称分配...
嗯,不!因为它不符合 the documentation :
In a function call, keyword arguments must follow positional arguments.
那么,星号在其他命名参数之前和之前做了什么?它是如何使用的?或者如果不使用它为什么会在那里?