This feature is fantastic and I haven’t seen it in any other language.
You don’t have to declare named arguments, all arguments are named with the argument names by default.
>>> def add(a, b, c): ... return a + b + c ... >>> add(1, 2, 3) 6 >>> add(c=1, b=2, a=3) 6
What happens if you mix in named args with positional args
>>> add(1, b=2, c=3) 6
That works, but if you change the order?
>>> add(a=1, b=2, 3) File "<stdin>", line 1 SyntaxError: non-keyword arg after keyword arg
That error is definitive which is great. What about using a named arg for an already declared positional argument? Another definitive error:
>>> add(1, a=2, c=3) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: add() got multiple values for keyword argument 'a'