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

I can someone give me a clue or explain how it'sdone?

If someone provides an answer for this code. can you explain it, please?

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
for continent in continents[0:3:5:6] :
    print(continents)

1 Answer

Hey man, if you remember in the previous tutorials, there is a way to retrieve the first character from a string. Here is how to do it

ps. this [0:3:5:6] I would not recommend you doing that because say for example they give you a random data that you can't see. this making this [0:3:5:6] unnecessary.

for continent in continents :
    # This is how you get the first character from a string
    # Ex.: A, .lower() just makes the letter a lower case
    # thus making the if statement true and printing the continent that begins with the letter 'A'
    if continent[0].lower() == 'a':
        print('*', continent)

hope this helps

Thanks!!! I had this in mind but I was not sure if I was right. Thanks for your help!