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 trial1 Answer
Duc Bui
14,546 PointsSometimes when you define a function and you don't know how many arguments you and someone else using your codes are gonna need, you use *args. For example:
def multiply(*args):
z = 1
for num in args:
z *= num
print(z)
multiply(4, 5)
multiply(10, 9)
multiply(2, 3, 4)
multiply(3, 5, 10, 6)
Output 20 90 24 900
Duc Bui
14,546 PointsSame idea for **kwargs.
Ewerton Luna
Full Stack JavaScript Techdegree Graduate 24,031 Pointsokay, but he never uses the args inside the code block, so why even put it in the function definition at all?
Duc Bui
14,546 PointsEwerton Luna he never uses it doesnt mean someone else won't, u should think of your codes are gonna be used by other coders as well.
I think Kenneth should make an example out of it (maybe he did, I just dont remember). I know it is hard to grasp some concepts in this series, I did not understand them at first either but stick to it.
Good luck and happy coding!
Dave StSomeWhere
19,870 PointsDave StSomeWhere
19,870 PointsIt allows you to pass an unknown number of arguments to a function and/or receive an unknown number of parameters into a function.
Here's a pretty good explanation in the answer of this SO Post