Skip to main content

How to Pass a List's Items as Separate Arguments in Python with * (Star)

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

When the arguments a function needs are already in a list, * in front of the list passes each item as a separate argument: area(*[3, 4]) works like area(3, 4). This guide spreads a list into two calls on Python 3.15.2.

Syntax​

Syntax
<function>(*<list>)
PartWhat it means
*Unpacks the list into separate positional arguments, in order
<list>A list, tuple or any other iterable with one item per argument

The Python language reference says: "If the syntax *expression appears in the function call, expression must evaluate to an iterable. Elements from these iterables are treated as if they were additional positional arguments."

The Example​

area takes a width and a height. A room's size is stored as a list, [3, 4]. The script spreads it into area, and then spreads another list into print.

Prerequisites​

  • uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with uv init.

Step 1: Write the Script​

area.py
def area(width, height):
return width * height


size = [3, 4]
print(area(*size))
print(*["a", "b", "c"])

The area.py script in a macOS-style code window: an area function with width and height, size = [3, 4], print(area(size)) and print(["a", "b", "c"]).

Step 2: Run It​

Terminal
uv run python area.py
Output
12
a b c

The terminal after uv run python area.py: 12, then a b c.

area(*size) ran as area(3, 4) and returned 12. print(*["a", "b", "c"]) ran as print("a", "b", "c"), which prints the three items with spaces between them. The command works unchanged in PowerShell.

Common Mistakes​

MistakeWhat happensDo this instead
More items than parameters: area(*[3, 4, 5])TypeError: area() takes 2 positional arguments but 3 were givenPass a list with exactly as many items as the function takes
Forgetting the star: area([3, 4])The whole list becomes width: TypeError: area() missing 1 required positional argument: 'height'Add the *

Troubleshooting​

SymptomLikely causeFix
takes 2 positional arguments but 3 were givenThe list has more items than the function has parametersCheck the list's length
missing 1 required positional argumentThe list was passed without *Write area(*size)

FAQ​

Does it work with a tuple?​

Yes. area(*(3, 4)) also printed 12. Any iterable works.

What's the double star for?​

** does the same for a dictionary, passing its keys and values as keyword arguments.

Conclusion​

area(*size) spread [3, 4] into width and height and returned 12, and print(*items) printed each item. The list needs exactly one item per parameter, and the star is easy to forget.

Additional Resources​