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 Python Basics (2015) Logic in Python Loop

Joseph Christianson
Joseph Christianson
435 Points

How do you incorporate the string added to World? I'm thinking it's %s but this one is really odd.

See above

loop.py
hellos = [
    "Hello",
    "Tungjatjeta",
    "Grüßgott",
    "Вiтаю",
    "dobrý den",
    "hyvää päivää",
    "你好",
    "早上好"
]

Hi Joseph,

What code have you tried? Are you able to create the for loop that would iterate through all the hellos?

3 Answers

Joseph Christianson
Joseph Christianson
435 Points

I see. Okay, so in trying to understand the logic of the programming language, how does Python know that's the right step? I just don't understand how a single value tells the program, okay grab these strings. Can you explain?

Haider Ali
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Haider Ali
Python Development Techdegree Graduate 24,728 Points

Hi Joseph, the way you concatenate 2 or more things together in python is by simply using a + sign. Here is what your code should look like:

hellos = [
    "Hello",
    "Tungjatjeta",
    "Grüßgott",
    "Вiтаю",
    "dobrý den",
    "hyvää päivää",
    "你好",
    "早上好"
]

for i in hellos:       #go through each string in hellos
  print(i + ' World')  #print the hello followed by the string ' World'
Joseph Christianson
Joseph Christianson
435 Points

Thanks for the speedy reply, Haider and Jason. what does the "i" serve as? As in, how does it bring each of those strings down?

Haider Ali
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Haider Ali
Python Development Techdegree Graduate 24,728 Points

Sorry, I assumed you had learned about this. Each time the loop happens, it goes through the hellos list and 'i' is the current item in the list. You do not have to write 'i' as it is just the name of a variable and can be called anything. However, it is very common that programmers use i and other short names like this.