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 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,702 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!