3 ms·
Python 3 lets you define functions with keyword-only arguments: >>> def foo(a, *, b="Default"): ... print((a, b)) ... >>> foo(1, b="bar")
by johnsoft 13y ago
Python 3 lets you define functions with keyword-only arguments:
>>> def foo(a, *, b="Default"):
... print((a, b))
...
>>> foo(1, b="bar")
(1, 'bar')
>>> foo(1, 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: foo() takes 1 positional argument but 2 were given
- agentultra 13y agoRight, I should've specified the Python version. Python 3's grammar for argument lists changed a bit and added kwonlyargs to the mix. IIRC the call node's arglist isn't just filled in left-to-right and handed names for keyword arguments anymore. Python 3 is definitely a step in the right direction. I wish adoption was a little more rapid.