Hacker News new | ask | show | jobs
by Cpoll 2562 days ago
In Python 3 at least, anything after the * args is a required keyword-only argument:

    >>> def a(b, *args, c): print(c)
    >>> a()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: a() missing 1 required positional argument: 'b'
    >>> a(3)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: a() missing 1 required keyword-only argument: 'c'
    >>> a(3, c=5)
    5
It's also valid to define it this way, if you don't need the * args:

    >>> def a(b, *, c): print(c)