Checking if a list has strings that begin with a certain letter.
"I'd like you to now only print continents that begin with the letter "A"." That is the task, but how do I check this?
continents = [ 'Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia', ] # Your code here for i in continents: print("* " + i)
Steven Parker177,709 Points
You can access individual characters in a string by indexing, using brackets similar to working with a list. For example, since index numbers start at 0, the first character of "mystring" would be "
You could then compare that to the letter "A" in a conditional expression as part of an "if" statement.
Alright, I got it now! Thank you for your help.
Oleksandr Krasnovskyy3,312 Points
Whats the final code? Doesnt work for me
for continent in continents: if i == "A": print("* " + continent)