Python Introducing Lists Using Lists Continental

Thabang Matlou
Thabang Matlou
2,419 Points

What do we do to print other items and exclude others from the list?

I'm stuck with the question whereby I have to print other items and leave others from the list.
continents = [
    'South America',
    'North America',
for continent in continents:
    print("* " + continent) 

1 Answer

Scott Bailey
Scott Bailey
13,172 Points

You can use an if statement.

As you are looking for items that begin with an "A" - you can select the first charecter in the word and compare it to "A".

if continent[0] == "A":

Remember python starts counting at 0, so the first charecter in the string is at [0]

If this comparision comes back as True it will execute the next indented code.