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 Creating Tuples

Lening Li
Lening Li
689 Points

Not sure how to create a variable called item3.

what's the value of item3? Tuple is immutable.

create_tuple.py
# insert your code here
my_tuple = 'I', 'love', 'python'

my_tuple = list(my_tuple)
my_tuple[2] =  'item3'
my_tuple = tuple(my_tuple)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,778 Points

Hey Lening Li, your first line is correct for Task 1. Items separated by comma form a tuple. Some coders wrap the items in parens to visually mark the tuple, but this is unnecessary as the commas make the tuple not the parens.

For Task 2, “item3” is a label so it goes on the left side of the =. On the right side goes the definition. Tuples can be referenced using indexing in the same manner as lists, so the third item can be referenced using [2]. More it is zero-based numbering: 0, 1, 2, etc. making 2 the third item.

Your second to last line of code above would be correct if the sides were switched around the equals sign. Since you’re defining a new variable and not a string, the quotation marks are not needed around item3.

Post back if you need more help. Good luck!!