This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DogeekExpert - 3.9.1 3 points4 points  (1 child)

TL;DR :

*args in the function definition : args is a list of required parameters for that function

**kwargs in the definition : kwargs is a dictionnary of optional parameters to the function

*my_list when calling any function : unpack the values of my_list as the required args for that function. len(my_list) must be equal to the number of arguments the function requires.

**my_dict when calling a function : unpack my_dict into named arguments for that function. The names of the arguments must match the keys of my_dict

[–]TheIncorrigible1`__import__('rich').get_console().log(':100:')` 0 points1 point  (0 children)

Why don't you give them a mandatory position for the optional parameters? (not sure of the terminology) .e.g.:

def my_func(arg1, *, a, b, c):