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

Brandon Evans
Brandon Evans
8,154 Points

Confused with this solution


I was able to solve this challenge, however I am confused why I am returned a tuple when I call this method, instead of the actual product I expect to see in console.

This is my code:

def multiply(*args):
    product = 1
    for arg in args:
        product *= arg
    return product

numbers = 1, 2, 3, 4, 5, 6


When I run this in console, the interpreter returns: (1, 2, 3, 4, 5, 6)

Should I not expect to see a single integer (the product) returned in the console? Or am I misunderstanding something?

Thanks for the help! :)

1 Answer

Steven Parker
Steven Parker
220,937 Points

The packing operator (*) is causing the tuple "number" to be handled as a single item. It would do what you expect if you passed a number of individual arguments (such as "multiply(1, 2, 3, 4, 5, 6)"). But when you pass a tuple in, you get the same tuple out.

But to make the function work on an iterable (like "number"), you'd want to remove the "splat": ("def multiply(args):").

Brandon Evans
Brandon Evans
8,154 Points

OOO! That makes perfect sense! :) I was oblivious to the fact the point of this challenge was to pass in multiple arguments lol. Duh. Perfect -- thanks so much for your explanation!