Python unpacking operator

allowing any number of arguments in a function
2025-11-21 15:37
// updated 2025-11-23 16:39

For situations in which we do not know how many arguments we will pass into a function, Python provides an "unpacking operator", denoted by an asterisk in front of the parameter's variable name:

def my_unpacking_function(*many_things):
  print(many_things)

The function will then take how ever many arguments and put them all into a list:

In fact, print() is the most well-known example of a built-in method in Python that unpacks an arbitrary number of arguments!

Other examples

Similar use cases with unpacking operator include:

  • selections of items to a playlist
  • adding items to a receipt
  • anything that involves one or more items
⬅️ older (in textbook-python)
📚 Python libraries (a quick how-to)
⬅️ older (in code)
🔢 NumPy essentials
⬅️ older (posts)
🔢 NumPy essentials