0

I've sometimes seen functions in help(...) defined like this:

def foo(x, *, y):
    ...

What does the lonely asterisk , *, in this function definition mean?

Searching for this answer online leads to lots of explanations of this other construction, which doesn't seem to me to be related:

def bar(x, *args, **kwargs):
    ...

A very similar thing is covered in the Python FAQs to describe a slash used like this:

>>> help(divmod)
Help on built-in function divmod in module builtins:

divmod(x, y, /)
    Return the tuple (x//y, x%y).  Invariant: div*y + mod == x.

So why is this related-seeming syntax with an asterisk not mentioned there? Where is it documented?

LondonRob
  • 73,083
  • 37
  • 144
  • 201
  • Also https://stackoverflow.com/questions/14301967/bare-asterisk-in-function-arguments – jarmod Jan 20 '22 at 15:57
  • The `/` is a much later (Python 3.8) addition to Python syntax than the `*` (Python 3.0). Both are documented in [Section 8.7](https://docs.python.org/3/reference/compound_stmts.html#function-definitions) of the [language reference](https://docs.python.org/3/reference/index.html). – chepner Jan 20 '22 at 15:59

0 Answers0