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 trialWilliam Ray Noble
22,190 PointsI'm sure I'm making an obvious mistake on a simple challenge but I don't see where I'm going on with unpacking.
So I'm not sure what I'm doing wrong. From what I can tell I've unpacked it into two variables. TAI
def unpacker(*args):
return args
val1 = unpacker('Python')
val2 = unpacker('rocks!')
2 Answers
Brian Davis
1,628 PointsI've been working this one for an hour, and it shouldn't be this difficult. I"m presuming that there is something in the instructions missing or something, as it should be easy. Any help?
nakalkucing
12,964 PointsHi William Ray Noble! Good job, you're close. At minute 1:00 in the video Unpacking, Ashley shows a similar example to what this challenge is looking for:
def unpacker():
return (1, 2, 3)
var1, var2, var2 = unpacker()
With the following explanation:
On the right side of this variable assignment, I'm calling the function, unpacker. Unpacker returns a tuple containing the values 1, 2, and 3. Because the left side of our variable assignment has more than one variable name, Python understands that we're trying to unpack this tuple. Just like passing multiple arguments to multiple parameters is positional, so is unpacking a sequence. In this example, the first element in the tuple 1 will be assigned to var1, ect.
Hope this helps! :) Post back if you need more help.
Brandon Pinnow
2,446 PointsHere is what I came up with.
def unpacker(*args):
return args
val1, val2 = unpacker('Python', 'rocks!')
print(val1)
print(val2)
treehouse:~/workspace$ python unpacking.py
Python
rocks!
nakalkucing
12,964 Pointsnakalkucing
12,964 PointsHi Brian Davis! Sorry it took me so long to get back. Are you still having a problem with this challenge? If so, please post your code below. Happy coding! :)