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 trial

Python Python Basics (2015) Python Data Types String concatenation

Patrik Karlsson
Patrik Karlsson
Courses Plus Student 436 Points

I don't understand how they want me to use the '+'

I don't understand how or where to place the '+' sign

name = "Patrik"
subject = "Treehouse loves"
subject + name

1 Answer

28,558 Points

The + is used to combine two strings, since "Treehouse loves" is a string and name is a string variable (which is treated identically to a string) you can combine them together directly on the second line like this:

name = "Patrik"
subject = "Treehouse loves " + name

Though one important thing to note is that when you combine strings using string concatenation they are glued together without any extra spacing added. So the code "Treehouse loves" + name would actually produce the string "Treehouse lovesPatrik" since there is no space at the end or start of the two strings. This issue can be solved by simply placing a space manually at the end of the first string like I have done in the code I demonstrated above this paragraph.