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 trialMostafa Raafat
5,979 PointsWhats the difference between returning a tuple and array
I cant get the difference between returning a tuple and an array. In both cases i return multiple values. And if i want to use the key value thing i can just use any collection like a dictionary. so Whats its edge ?
2 Answers
Eric Gu
3,871 PointsWith tuples, you have the ability to return a collection type consisting of different data types.
With arrays, all the items in the collection type must be of the same data type.
Akilah Jones
18,397 PointsAlso using tuples is more efficient...
(value1, value2, value3) = functionThatReturnsTuple
value = functionThatReturnsArray
value1 = value[0];
value2 = value[1];
value3 = value[2];
Samar Khanna
1,757 Pointsi didn't get what u said
Akilah Jones
18,397 PointsSamar Khanna what I was trying to demonstrate is the difference in using a tuple to store data versus using an array to store data...
When using a tuple, as shown above, it only takes one line
(value1, value2, value3) = functionThatReturnsTuple
Where as using an array, to do the exact same thing, takes four lines
value = functionThatReturnsArray
value1 = value[0];
value2 = value[1];
value3 = value[2];
I hope that helps
Akilah Jones
18,397 PointsSamar Khanna what I was trying to demonstrate is the difference in using a tuple to store data versus using an array to store data...
When using a tuple, as shown above, it only takes one line
(value1, value2, value3) = functionThatReturnsTuple
Where as using an array, to do the exact same thing, takes four lines
value = functionThatReturnsArray
value1 = value[0];
value2 = value[1];
value3 = value[2];
I hope that helps