Python Introducing Lists Using Lists Continental

Jose Ramirez
Jose Ramirez
7,826 Points

How to get the countries with letter A

How to select the countries with letter A in this quiz?

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
print("Continents:")
for continent in continents:
    print("* " + continent)
James Reinhold
James Reinhold
12,359 Points

I have used a string method . startwith() to perform this function:

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
print("Continents:")
for continent in continents:
    if continent.startswith("A"): # Returns True
        print(continent)

But if you want all the continent that contains letter "A" , you can use the "in" keyword

for continent in continents:
    if "A" in continent:
        print(continent)

1 Answer

Jose Ramirez
Jose Ramirez
7,826 Points

Thank you very much James.