Splat
What is splat
Splat is *
or **
. And why do we use splat?
Python supports functions with an uncertain number of parameters. The splat operator provides an artistic way of unpacking argument lists.
Positional arguments vs keyword arguments
Positional arguments are arguments without default values while keyword arguments are arguments with default values. Both the number of positional arguments and the number of keyword arguments could be uncertain:
1 | def func(*args, **kwargs) |
Argument lists
To call the function with uncertain arguments, we could pass the argument one by one:
1 | x = 1 |
However, we could also pass an argument list and use splat to unpack the list:
1 | test_list = [1, 2, 3] |