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 trialmohan Abdul
Courses Plus Student 1,453 Pointsprint 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 = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
for continent in continents:
print("* " + continent)
print(continent [0])
2 Answers
Steven Parker
231,198 PointsYou 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".
Mil Kapil
15,484 PointsYour 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.
mohan Abdul
Courses Plus Student 1,453 Pointsmohan Abdul
Courses Plus Student 1,453 PointsSteven 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
231,198 PointsSteven Parker
231,198 PointsTesting "
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".