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 trialChristopher Sullivan
4,230 PointsChallenge Task 2 of 2 Create a variable called item3 and assign to it the third element in my_tuple.
Hey Good morning everyone,
I am looking for some assistance on how to add the variable item3 that I created to the third element. I tried .add but I am still receiving errors.
my_tuple = 'I', 'love', 'python' item3 = ['3']
my_tuple = 'I', 'love', 'python'
item3 = ['3']
2 Answers
Paul C
2,668 PointsThe question is not asking you to literally add item3 to the existing tuple, but rather to create a new variable (item3) from the existing 3rd element from my_tuple.
At first I was confused because we know tuples are immutable, and don't allow for object assignment after they have been created.
Eventually I could see it was only asking for us to pick out the 3rd element of my_tuple, which is my_tuple[2] and create a new variable from it. Therefore the code looks like this:
my_tuple = ('I', 'love', 'python')
item3 = my_tuple[2]
Steven Parker
231,275 PointsWhen indexing, the name of the item ("my_tuple" in this case) must come before the brackets.
Also, a numeric value should never be enclosed in quotes. That creates a string instead of a number.
Finally, index values start at 0, so you should always reduce the index by 1. The index for the third item will be 2.
Christopher Sullivan
4,230 PointsThank you! This helped out. I was able to run it and cleared the question.
Steven Parker
231,275 PointsChristopher Sullivan — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!
Christopher Sullivan
4,230 PointsChristopher Sullivan
4,230 PointsThanks it ran!!! I think my issue was as you stated, I was trying to actually add item3 to the existing tuple.