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

How do i assign a variable to an element in a tuple

Where exactly am i going wrong

1 Answer

Chris Kisselburgh
Chris Kisselburgh
2,173 Points

Hey 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!