函数声明中单独的星号 * 是什么意思?

What does a star * alone mean in a function declaration?

以下代码中的 * 是什么意思(在 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.

那么,星星在其他命名参数之后和之前做了什么?它是如何使用的?或者如果不使用它为什么会在那里?

当没有可变参数时,它将位置参数与 keyword-only arguments 分开。这是 Python-3 独有的功能。