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 Functions and Looping Returning Values

walter fernandez
walter fernandez
4,992 Points

I need help

I want to write an expression that whose value is the fifth character of the String name.

This is what I did, but It is wrong.

name = "walter." letter = name[5] print(letter)

2 Answers

Brendan Whiting
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,734 Points

Array or string indices in python are 0-based. Which means the first character in the string can be found at name[0]. So you always have to subtract 1. The fifth character is at name[4]. You'll get used to it.

When you are selecting a character in a string by index, you need to start by index 0. So for example, name[0] would give you 'w'. name[1] would give you 'a'. So in this case, you need to subtract one from 5 to give you four. So name[4] would give you the fifth letter of the name, which is 'e'. I hope this helps!