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

Angel Naranjo
Angel Naranjo
30 Points

Someone, please help me understand how to read this code.

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

Why does the "if continent[0]" have only the zero, wouldn't that only target just Asia?

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

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

continentS is the list, so continentS[0] would be Asia, but continenT is each item in the list in the for loop. continenT[0] would therefore be the first letter in each continent's name

Angel Naranjo
Angel Naranjo
30 Points

The variable "continents" is a placeholder for the set of string values, so "continent" is the variable name that is a placeholder for "continents". "continents[0]" is "Asia," NOT continent[0].

continent[0] is every first letter of each list item.

Thank you, James.