What does only star * mean in function declaration?

What does * mean in the following code (found in the pprint library)?

 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) 

If it was *args , then this would be an arbitrary number of positional parameters. The parameter values ​​will be in a tuple called args . The first 4 parameters can be assigned either by name or by position, the compact parameter can be assigned only by name ...

Well no! Because he does not agree with the documentation :

In a function call, the keyword arguments must follow the positional arguments.

So what does a star do after and before other named arguments? And how is it used? Or why is he there if he is not used?

+7
python syntax parameter-passing
source share
1 answer

It separates positional arguments from keyword-only arguments when there are no variables. This is a Python 3 feature.

+10
source share

All Articles