Python Python Basics (2015) Logic in Python Loop

Maria Cuevas
Maria Cuevas
2,001 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,671 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
PRO
Hirenkumar Patel
Pro Student 9,185 Points

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

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