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 trialFarai Ted Mandoreba
21,518 Pointsi need help on this one guys i am a bit stuck here on this task
Challenge Task 1 of 1 Edit the variable assignment under the provided function so that the tuple returned from the function call is unpacked into 2 variables, val1, val2
def unpacker(*args):
return args
val = unpacker('Python', 'rocks!')
Hรฅvard Hytten
6,239 PointsYou should atleast make an attempt of solving it before going stright to the community. A good pointer is to move the values to the return statement. It should look like this - return ('Python', ' rocks!'). From there you should look into Steven's suggestion from earlier. Happy coding mate.
Brent Rainwater
2,029 Pointsperhaps he did try it out before he came here - like I'm doing. Perhaps you should help instead of hindering - happy coding mate
Brent Rainwater
2,029 Pointsso here's how I did it val1, val2 = ("Python rocks").split(' ') and from there I jut printed the values - worked like a charm - good luck to you
6 Answers
Baitsheletse Thokwana
4,136 Pointsdef unpacker(*args): return args val1, val2 = unpacker('Python', 'rocks!') print(val1) print(val2)
Michael McGill
2,085 Pointsdef unpacker(*args):
return args
val1, val2 = unpacker('Python', 'rocks!')
This worked and I didn't need to put in the print function
Christopher Sullivan
4,230 PointsDont know why, but came with the same solution but it didnt take my code. But if I copy/pasted your the checker works?
Farai Ted Mandoreba
21,518 Pointsthis was my answer thanks a lot guys you are so patient,
def unpacker(*args): return args val = unpacker('Python', 'rocks!') val1 = "Python" val2 = "rocks!"
Farai Ted Mandoreba
21,518 Pointsthank you guys you helped me a lot, i was not referencing correctly to the second value rocks!, i was doing an error, i was leaving out the '!' like val2 = rocks instead of val2 = rocks!
ERDAL DINCER
1,635 Pointsdef unpacker(*args): val1, val2 = unpacker[0] ,unpacker[1] return val1, val2 unpacker('Python', 'rocks!')
What is my mistake ?
Christopher Kehl
18,180 Pointsdef unpacker(*args): return args
val1, val2 = unpacker('Python', 'rocks!')
Unsubscribed User
8,947 PointsUnsubscribed User
8,947 PointsCurrently, the function unpacker returns a tuple of the arguments provided when running it:
val = ("Python", "rocks!")
The video just before this challenge provides the syntax for assigning each list item to a variable: