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) Tuples Packing

tuples multiply,slice

Let's play with the *args pattern. Create a function named multiply that takes any number of arguments. Return the product (multiplied value) of all of the supplied arguments. The type of argument shouldn't matter. Slices might come in handy for this one.

def multiply( args): pro=1 for v in args: pro=v return pro multiply(3,5)

HERE I DID'NT USE ANY SLICES BUT THE TASK WAS COMPLETED WHY?

1 Answer

Steven Parker
Steven Parker
230,995 Points

The instructions said "Slices might come in handy for this one." But there are many ways to get the same result, and only some of them would use slices.

Your solution is effective and concise. Good job! :+1:

Jimmy Otis
Jimmy Otis
3,228 Points

Steven, I too came out with the same code as the poster of this question. However I am curious, how would one utilize slices to reach the same result?

Steven Parker
Steven Parker
230,995 Points

Instead of starting with 1 and then multipying it by each element, you could also start with the first item and then multiply by each of the others. A slice could be used to make a list containing all the items after the first.