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 Introducing Lists Using Lists Continental

Accessing specific characters in a string by index

I’m having difficulty understanding how to do this (part 2 of this quiz). I want to print each continent that begins with “A” in this quiz. I thought if I specified the index and “A” that it would work, but I guess not.

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
for continent in continents:
    print("* " + continent[0, "A"])

2 Answers

Steven Parker
Steven Parker
229,732 Points

The index should be just a number. You'll need a separate conditional statement ("if") to compare the indexed character to "A" and control the "print" statement based on the result.

Thanks for the reply. I've tried the "if" statement with the index of [0] = "A" but it keeps reading only the first continent in the list, rather than the first letter of each continent.

Steven Parker
Steven Parker
229,732 Points

Please show the complete code after the changes.

I ended up getting it figured out. Your initial tip helped out, just had to keep working on it. Thanks!