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 trialMalcolm Aldrin Masumba
3,689 PointsHow do i assign a variable to an element in a tuple
Where exactly am i going wrong
1 Answer
Chris Kisselburgh
2,173 PointsHey Malcolm,
Remember that tuples are immutable meaning they can't be modified once the data is stored inside of one. With that in mind, you access items in tuples using their position index inside of square brackets.
my_tuple = ('dog', 'cat', 'bird')
print(my_tuple[1])
This code should return the string 'cat' as the position index in python always starts at the number 0. Instead of printing the variable like I did in my example, you could just assign it to a new variable as well.
Hope this helps!