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 trial

Python Functions, Packing, and Unpacking Packing and Unpacking Packing

Basel Kanaan
Basel Kanaan
4,458 Points

whats the different between **kwargs and *args is the first one only used for dictionaries?

and can we use the second one dictionaries also?

1 Answer

Steven Parker
Steven Parker
229,582 Points

The conventional name "kwargs" stands for "keyword arguments" which are key/value pairs. The double-asterisk packing operator is specifically for converting these pairs into a dictionary.

On the other hand "args" are just simple arguments, and the single "splat" converts them into a list.

The names themselves are simply conventions, but mixing them up could be very confusing for another Python developer!

@Steven Parker, I thought the single asterisk converted them into a tuple, not a list?