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 trialIan Cole
454 Points*args confusion
If I could get some pointers for this that would be great, but im more just wanting some help trying to understand this. What does *args
even do? I was also confused by **kwargs
that was used with dictionaries so I think it's safe to say im effectively lost
def multiply(*args):
1 Answer
Steven Parker
231,269 PointsThe "splat" operators do two different things based on where you use them. When used on a parameter in a function definition (as you show above), it is known as the "packing operator" and it means "collect all the individual arguments into a list and call it by this name". Inside the function, you might use the list as an iterator in a loop.
But elsewhere it is the "unpacking operator" and means "expand this list into separate items".
The double version "**
" does a similar job but with dictionaries instead of simple lists.