Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
210,850 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?