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 trialJorgen Rasmussen
3,367 PointsThe question Select any valid tuples: seems to have no correct answers. None end with a comma
None of the answers seem correct as we were told in the instructions that a tuple must have a comma after every object including the last one, correct?
2 Answers
johndavidsnieg
2,146 PointsThe only time that the last object in a tuple is required to be followed by a comma is when the tuple contains only one object, so the comma shows that it is a tuple not just a single object contained in a variable. For example: if you wanted the variable "var" to contain the integer 1 you could write
#Not a tuple
var = 1
But if you wanted var to contain a tuple with only one value, you would write
var = 1,
#or if you wanted to use parentheses
var = (1,)
But when you have multiple items in a tuple, you do not need to have a comma after the last one as the interpreter is able to determine it is a tuple by the syntax of the previous objects in the tuple.
mon Wil
2,007 PointsThanks for clarifying this!
Jorgen Rasmussen
3,367 PointsJorgen Rasmussen
3,367 PointsHi Johndavidsnieg, Thank you for your reply. This makes sense