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 don't quite understand what I am doing wrong.

I watched the video 5 times and I feel like I am missing something with this code challenge.

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

3 Answers

Jerson Otzoy
Jerson Otzoy
1,532 Points

Hope this helps

numbers = [1, 3, 5]

Say that we want to square each of the numbers in this list

for number in numbers:
    print(number * number)

If you run this the result would be this

1
9
25

What happened here step by step is:

  1. We set a list (numbers) with five elements.
  2. The program takes the first element from the list and store it in a variable called number.
  3. The result of the operation number * number is printed. (In this case for the first element 1, the result is 1)
  4. Then the program does this same operation for the remaining elements in the list.

Basically we are telling the program to do something with each element in the list, and we are referring to that element by the name number.

Ohhh I think I get it now. so we use for to create a new variable to modify whatever element we want in the list and you can also specify parts of the list with indexing. Does that sound about right or am I off a bit?

Jerson Otzoy
Jerson Otzoy
1,532 Points

Yes, that sounds about right.

Jerson Otzoy
Jerson Otzoy
1,532 Points

Hello, since you are iterating in the list you should use the element variable name instead of the list name inside the for loop:

    print("* " + continent) 

Can you explain in a bit more detail please. I don't get this for and in concept of for and in