What does ** (double star/asterisk) and * (star/asterisk) do for parameters in Python?

The *args and **kwargs is a common idiom to allow arbitrary number of arguments to functions as described in the section more on defining functions in the Python documentation. The *args will give you all function parameters as a tuple: def foo(*args): for a in args: print(a) foo(1) # 1 foo(1,2,3) # 1 # 2 … Read more

Unpacking, extended unpacking and nested extended unpacking

My apologies for the length of this post, but I decided to opt for completeness. Once you know a few basic rules, it’s not hard to generalize them. I’ll do my best to explain with a few examples. Since you’re talking about evaluating these “by hand,” I’ll suggest some simple substitution rules. Basically, you might … Read more

What does ** (double star/asterisk) and * (star/asterisk) do for parameters?

The *args and **kwargs is a common idiom to allow arbitrary number of arguments to functions as described in the section more on defining functions in the Python documentation. The *args will give you all function parameters as a tuple: def foo(*args): for a in args: print(a) foo(1) # 1 foo(1,2,3) # 1 # 2 … Read more