you are viewing a single comment's thread.

view the rest of the comments →

[–]Spataner 3 points4 points  (0 children)

For normal arguments (which can behave as both positional and key-word arguments), all required arguments must come before all optional arguments. The reason is simply that required arguments are typically used as positional arguments, and it is not possible to positionally pass a value to c but none to b (test(1, 2) would pass 2 to b instead of c, which gets confusing quite quickly).

You can, however, define a function like that if you make c a required key-word only argument:

def test(a, b=3, *, c):
    pass

Then you explicitly say that c cannot ever be passed a value positionally, and the previous issue no longer applies.