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 trial

Python Python Basics (2015) Python Data Types Specific Index value

Alexandre Gagarochkine
Alexandre Gagarochkine
426 Points

One more thing to practice.

Make a new variable, var_two, with "e" at index -2. Remember, negative indexes start at the right side of the iterable.

index.py
var_one = ['a','b','c','d','e', 't']
var_one = [-2]

2 Answers

Sean May
Sean May
9,145 Points

It's asking you to set the letter e to what would be the -2 index of the list. When you're doing negative counting in Python, you start from the right and work to the left. So, you need to set e to be the second character when you start counting the list from the right.

I'm stuck on this as well. :/ Can someone please post what the answer should look like? Thanks.

Update:

Somehow this worked for both:

var_one = ["a", "b", "c", "d", "e", "t"] var_two = ["a", "b", "c", "d", "e", "t"]

I... I don't know what I'm doing. >.>

Sean May
Sean May
9,145 Points

It worked because it's correct :)

To elaborate on that more, the first part of the challenge calls for you to make a variable with t at the 5th position in the index. Because Python (and many other languages) starts indexes with 0, the first character is in the 0th position, the second at the 1st position, and so on. So, var_one = ["a", "b", "c", "d", "e", "t"] works for the first challenge because t is at the 5th index position by being the 6th character since we start counting from 0. Another acceptable answer would be var_one=["abject"] or var_one=["adjust"] since your answer could be a string or a list. If you really wanted to supply an annoying (but correct) answer, you could also answer var_one=["tttttttttttttttt"]

For the second challenge, the thing to know here is that when you're using negative indexing in Python, you start counting from -1. So the last character in a string is in the -1st position, the second at -2, the third at -3, and so on. So, it's pretty straightforward, the -2nd character in the string should be in the second position when you start counting from the right, which is why your answer worked.