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

Continental task 2

I understand the concept and know what to put in the box but can someone explain to me why I had to put [0] next to the continent Plz, explain thx :)

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

# Your code here

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Sean Layton ! The reason is that we only want to check if the first letter of the continent is "A", not the entire continent name. So on the first iteration, continet (as you named it) will be equal to "Asia". But "Asia" is not equal to "A". It does, however, begin with "A".

Just like lists can be accessed with indexes, so can strings! If we were to have a variable greeting = "Hello" then greeting[0] would be "H" and greeting[4] would be "o". Here we're checking only the first letter of that string and the first letter resides at index 0.

Hope this helps! :sparkles:

ohhhhh thank you so much it makes so much sense :)!