Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,724 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,724 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.