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 Python Collections (2016, retired 2019) Dictionaries Packing and Unpacking Dictionaries

Why when I try to pass a value to *arg it doesn't get passed to it.

I'm trying to catch second_color outside of the packing, and pass "I'm a tuple" to *args and print out both args and kwargs. Here's my example:

def color(second_color = None, *args, **kwargs): print(kwargs) print(args)
color(second_color= "Brown", "I'm a tuple", first_color= "Red", last_color= "Blue")

SyntaxError: positional argument follows keyword argument

1 Answer

Kent ร…svang
Kent ร…svang
18,823 Points

You need to remove the "second_color"-keyword from your function-call.

    color("Brown", "I'm a tuple", first_color= "Red", last_color= "Blue")

You can read about why here if you are interested

Also, remember that kwargs are dictionaries. So if you want to print them out you should use dict().items() and a for-loop:

    for item in kwargs.items():
        print(item)

for the args you can just use a basic for-loop:

    for item in args:
        print(items)

I hope this helped