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 trialilya A
3,802 PointsHow do I add?
I cannot seem to be able to add "world" to each item in the list...
hellos = [
"Hello",
"Tungjatjeta",
"Grüßgott",
"Вiтаю",
"dobrý den",
"hyvää päivää",
"你好",
"早上好"
]
for world in hellos:
print(world)
3 Answers
ds1
7,627 PointsThe pattern for a "for" loop is "for [item] in [container]:". In this exercise, the container is a list of hellos. So do we really want to name the [item] variable "world"? That may be confusing you... I'd name it something else. Also, how do you use quotation marks to tell Python that some bit of text is a string? Now, how do you concatenate the [item] variable in your "for" loop with the bit of text you just typed in? If you know how to answer these 3 questions, you'll have all you need to complete this exercise! Thanks, D.
ds1
7,627 PointsHi!
Here are a couple of ways you can do this:
1) You could use string concatenation ("+")
or
2) You could use the "format()" function.
ilya A
3,802 PointsCould you walk me through using the first method?
ds1
7,627 PointsI'd suggest watching the "Strings" video (in the Python Data Types section) again... about 3:30 into the video should help, but feel free to watch all of the video again as strings are used alot in Python. Also, think of the 'for' line as "for [item] in [something]:" as in "for hello in hellos:"
Thanks! D.
ilya A
3,802 Pointshellos = [
"Hello",
"Tungjatjeta",
"Grüßgott",
"Вiтаю",
"dobrý den",
"hyvää päivää",
"你好",
"早上好"
]
for world in hellos:
print(hellos + world)
The error appears: "Bummer! can only concatenate list (not "str") to list"