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

mohan Abdul
PLUS
mohan Abdul
Courses Plus Student 1,453 Points

print continents that begin with the letter "A". accessing characters in string by index

yeh, i am kind of stuck, i can only access first character of a word using character indexing.

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

print(continent [0])

2 Answers

Steven Parker
Steven Parker
231,275 Points

You don't need to "print" the first letter. Instead, compare the first letter to "A" as part of an "if" statement placed between the loop and the existing "print".

mohan Abdul
mohan Abdul
Courses Plus Student 1,453 Points

Steven Parker
i finally sort of think what you mean, task11.py i placed the is statement between exiting for loop and existing print but still nothing is happening. https://w.trhou.se/sbcbmjff29

Steven Parker
Steven Parker
231,275 Points

Testing "if 'A' in continent" will return each name that has "A" in it anywhere, not just at the beginning. So you were on the right track to isolate the first character as "continent[0]". Now just check of that is equal to "A".

Mil Kapil
Mil Kapil
15,484 Points

Your code:

for continent in continents:
    print("* " + continent)

is good. continent[#] will provide the # indexed component of the string. The provided list is continents. Note the difference variable.