Python unpacking operator
allowing any number of arguments in a function
2025-11-11 15:37
// updated 2026-01-06 16:22
// updated 2026-01-06 16:22
For scenarios 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)In fact, print() is the most well-known example of a built-in method in Python that unpacks an arbitrary number of arguments!=
The function would then take however many arguments and put them all into a list:
Similar use cases with unpacking operator include:
- selections of items to a playlist
- drag-and-drop any number of files for upload
- anything that involves one or more items at a time
Sure, we could also just pass in a list as an argument but where's the fun in that?