Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAbubakar Gataev
2,226 Pointswhat is *args and what does it do?
What does args do and what does it mean I completly don't get . please help
3 Answers
Steven Parker
231,275 PointsThe "packing/unpacking" operator (also known as "gather/spread" or just "splat") does one of two things based on where it is used.
In a function definition, it causes individual arguments passed to the function to be gathered together into a single list with the name given after the "*" ("args" in your example):
def foo(*args)
this definition, and this call foo(a, b, c)
...would be the same as...
def fum(args)
this definition with this call fum( [a,b,c] )
Elsewhere in the code, it causes a list to be expanded into a set of individual arguments:
bunch = [1, 2, 3]
x = somefunc(*bunch) # this is the same as: x = somefunc(1, 2, 3);
Abubakar Gataev
2,226 PointsThanks! I get it now.
Jonathan Ng
7,982 PointsThank you!
diego cortes
1,421 Pointsdiego cortes
1,421 PointsThank you Steven, your examples make it easier for me to understand the concept