What Are Python Asterisk and Slash Special Parameters For?

Whenever you think of Python’s asterisk operator (*), you most likely think of multiplication or exponentiation. Similarly, you probably associate the forward slash operator (/) with division. But you can also use the bare asterisk and slash as special parameters in function headers. These do something completely unrelated to mathematics.

When defining functions, you’ll often include a list of comma-separated parameters to define what types of arguments the user can pass to your function. Using the asterisk and forward slash symbols as special parameters in your function header may look strange at first:

def strange_function(*, x, y):
...

def another_strange_function(a,

 

 

 

To finish reading, please visit source site