-2

In a function parameter list, a parameter without a default cannot occur after a parameter with a default,

def func(a, b=2, c, d=4, e): .... ERROR

unless this is after *:

def func(a, b=2, *, c, d=4, e): .... OK

Why are non-default arguments permitted after default arguments after *?

Owen
  • 38,836
  • 14
  • 95
  • 125
zer0uno
  • 7,521
  • 13
  • 57
  • 86
  • 1
    Have you read [PEP-3102](http://legacy.python.org/dev/peps/pep-3102/)? This covers the *"'single star' syntax for indicating the end of positional parameters"*. – jonrsharpe Aug 27 '14 at 10:26
  • [similar question here](http://stackoverflow.com/questions/14301967/python-bare-asterisk-in-function-argument) – Holloway Aug 27 '14 at 10:27
  • I know that paremeters after `*` are just keyword-only arguments. The doubt is not about that. The question is: Why allowing a mixture of default and no default after * and not before *? – zer0uno Aug 27 '14 at 10:28
  • 1
    So where is the confusion? In the first, there is no way of passing `e` without passing `b`, `c` and `d` first (as it's positional). With the second you're forced to name them all. so it doesn't matter. – Holloway Aug 27 '14 at 10:30
  • 2
    Because arguments without default values prior to a single `*` are positional arguments, whereas those after are keyword-only-no-default. Please just read the PEP, it explains the rationale for introducing the syntax. – jonrsharpe Aug 27 '14 at 10:33

1 Answers1

0
func(2, 2, 2, 2)

What would that mean in the context of your first example?

BartoszKP
  • 34,786
  • 15
  • 102
  • 130