Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Python Data Types String concatenation

Not sure why this is incorrect? name = "Anne" subject + = "Treehouse loves" + "name" Thanks Thanks

Not sure why this is incorrect?

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

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! There's a few minor things going on here. First, you have subject +=. This would concatenate the string following the equals sign to the string currently in subject, but this is the first time subject is declared so there is no string there. Here you only need subject =.

If we were to fix that and then print out that string that you have coded it would print out "Treehouse lovesname". Note that there is no space between the "loves" and the "name". Furthermore, you are using the string literal "name" instead of of the value in the variable name. Removing the quotes from around the name tells Python to use the value of that variable.

Here's an example:

student = "Jennifer"
greeting = "Hi there, " + student

The string stored in greeting would be "Hi there, Jennifer". Notice how I included an extra space after the comma in the string literal part to make sure that "Jennifer" wouldn't be smushed up against the comma like this: "Hi there,Jennifer".

Hope this helps, but let me know if you're still stuck! :sparkles:

Very clear. Appreciate your time!

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

Hello Truthseeker. The truth is that when you create the subject variable you should assign the string to it notadd the string to it

subject =  "Treehouse loves" + name

instead of

subject += ...<rest of the code>

And when you add the name variable to the subject, it should be added the name variable and not the "name" string In your code the subject var it's not yet defined to able to add something to it So the final vode should look like this

subject = "Treehouse loves" + name

I hope it helps you. Happy coding

Thanks!