*args and **kwargs

alister alister.ware at ntlworld.com
Fri Sep 2 10:52:13 EDT 2016


On Fri, 02 Sep 2016 23:44:50 +1000, Ben Finney wrote:

> Smith <smith at smith.com> writes:
> 
>> I'm trying to understand the concept of * args and ** kwarg with
>> python3
> 
> Welcome. Your questions are fine in this forum; but you may also want to
> participate in our collaborative learning forum for Python beginners,
> <URL:https://mail.python.org/mailman/listinfo/tutor>.
> 
>> But I can not understand why I returns the error message "SyntaxError:
>> positional argument follows the keyword argument" when I insert values.
> 
> It's fairly simple (though it may not be obvious!):
> 
>> In [23]: start(data="Fish",2,3,tox="tux")
>>   File "<ipython-input-23-eb9c3abb9941>", line 1
>>     start(data="Fish",2,3,tox="tux")
>>                      ^
>> SyntaxError: positional argument follows keyword argument
> 
> Exactly.
> 
> Note that this has nothing to do with how the function is defined; in
> the definition of the function, parameters are neither positional nor
> keyword. You name each of them, and you define an order for them; and
> neither of those makes any of them “positional” or “keyword”.
> 
> Rather, “positional argument and “keyword argument” are characteristics
> of the arguments you *supply* in a particular call to the function.
> 
> You have specified four arguments, in this order:
> 
>   * A keyword argument, ‘data="Fish"’.
>   * A positional argument, ‘2’.
>   * A positional argument, ‘3’.
>   * A keyword argument, ‘tox="tux"’.
> 
> After specifying a keyword argument, you may not then specify any
> positional arguments. Hence the SyntaxError.


& the solution is to change the order of the definition

def start( must_have,*args,**kwargs,data=none):
 


-- 
Pretend to spank me -- I'm a pseudo-masochist!



More information about the Python-list mailing list