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

SISLEY NGUYEN
SISLEY NGUYEN
1,835 Points

OK! Make a new variable named subject that concatenates (uses the + sign) the string "Treehouse loves" and your name var

OK! Make a new variable named subject that concatenates (uses the + sign) the string "Treehouse loves" and your name variable.

strings.py
name= "Sisley"
subject="Treehouse loves"
subject+="Treehouse loves"+"Sisley"

1 Answer

You don't need the second line of code.

If you checked what subject was after this code has been run, it would be:

Treehouse LovesTreehouse LovesSisley

And no, I'm not joking. Try printing out subject in Workspaces (after this code) and seeing the same result.

This is because you are assigning "Treehouse Loves" to a variable called subject then later adding on another "Treehouse Love" and your name.

If you remove the second line of code, you should get this result (a little better):

Treehouse LovesSisley

Now, the reason there's no space between "Treehouse Loves" and your name is because you didn't specify a space. Python is really picky about your code, you you have to explicitly say there's supposed to be a space there.

If you fix the last line of code, your code should look like:

name = "Sisley"
subject = "Treehouse Loves" + " " + name

And your result:

Treehouse Loves Sisley

I hope you understand now :)

Good luck! ~alex