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

Alma Cuevas
Alma Cuevas
2,703 Points

for words in hellos: print(hellos + 'World') Bummer! can only concatenate list (not "str") to list

Why does it say that?

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

for words in hellos:
    print(hellos + 'World')

2 Answers

AJ Salmon
AJ Salmon
5,675 Points

The error is being raised because you're trying to concatenate the list hellos with the string "World". Instead of printing hellos + " World" you need to print words + " World". When you use a for loop, the first name you give it (example: 'x' in for x in y) represents each item in the iterable you give it, which is the second object that comes after the 'in'. Also, make sure you include an extra space at the start of your string! You want it to print "Hello World" not "HelloWorld".

Put words instead hellos and add space Before World See as under

for words in hellos: ti = words + " World" print(ti)