Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Introducing Lists Using Lists Continental

Ajet Shabani
Ajet Shabani
439 Points

I'd like you to now only print continents that begin with the letter "A". someone explain me this

continents = [
    'South America',
    'North America',

for continent in continents:
    print ('*', continent)

2 Answers

Steven Parker
Steven Parker
218,596 Points

By indexing with brackets, you can isolate the first character of a string. For example, the first letter of name would be name[0]. Then, it's a simple matter to compare it to what you are looking for.

Asher Orr
.a{fill-rule:evenodd;}techdegree seal-36
Asher Orr
Python Development Techdegree Graduate 9,086 Points

Hi Ajet!

In challenge task 1 of 2, you looped through each continent in the list "continents" and printed it next to a bullet point. Nice work!

For challenge task 2, the one you're asking about, you need to modify the code so that it prints out the continent ONLY if the first letter starts with A.

Your code needs a conditional statement to make this work. Conditional statements use the operators if, elif, and else.

Here's an example:

x = "Ajet"
if x == "Ajet":
    print("The variable x stores the value 'Ajet'")
    print("The variable x does not store the value 'Ajet'")

If you ran this code, "The variable x stores the value 'Ajet'" would print to the console.

But if you changed x to "Asher", like this:

x = "Asher"
if x == "Ajet":
    print("The variable x stores the value 'Ajet'")
    print("The variable x does not store the value 'Ajet'")

"The variable x does not store the value 'Ajet'" would print to the console.

To solve the challenge, you need to print the continent only if the first character is A. Remember that you can access characters in a string by index. Let me show you an example.

my_list = [
for number in my_list:

The code above would print this to the console:


To solve the challenge, your code should incorporate both concepts (conditional statements and accessing characters in a string by index.)

I hope this helps! Let me know if you have additional questions.