Python Python Basics (2015) Logic in Python Loop

Maria Cuevas
Maria Cuevas
2,496 Points

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

Why does it say that?
hellos = [
    "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".

Hirenkumar Patel
Hirenkumar Patel
Pro Student 9,463 Points

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

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