Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Introducing Tuples Getting to Know Tuples Getting to Know Tuples Recap

Jorgen Rasmussen
Jorgen Rasmussen
3,367 Points

The 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?

1 Answer

The 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.

Jorgen Rasmussen
Jorgen Rasmussen
3,367 Points

Hi Johndavidsnieg, Thank you for your reply. This makes sense