Python Introducing Lists Using Lists Continental

Anders Axelsen
Anders Axelsen
3,470 Points

How do I make an if-statement of which the condition is a string in the list, continents, starting with the letter 'A'?

Here is my attempt on finding a as the first letter of the list item. #fail

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

Do you have specific advice? Please share.

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 24,835 Points

You're very close. The way to check the first letter being "A" is slightly simpler that you had.

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
print("Continents:")
for continent in continents:
    if continent[0] == "A":
        print("* " + continent)
Anders Axelsen
Anders Axelsen
3,470 Points

You're right! How satisfying to see the content of the video lesson being truly relevant to the task.

Anders Axelsen
Anders Axelsen
3,470 Points

I found out to index the individual continent as such:

for continent in continents:
    if continent[0] == "A":
        print("* " + continent)