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 trialMargaret Maginnis
199 Pointsname = "margaret" subject = "Treehouse loves + name"
In python I want to concatenate the subject "Treehouse loves" + name, so I wrote
name = "margaret" subject = "Treehouse loves" print (subject + name)
Obviously this is wrong but I'm not sure why
name = "margaret"
subject = "Treehouse loves" + name
6 Answers
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsYou just need a space in there, otherwise the result will be "Treehouse lovesmargaret"
Margaret Maginnis
199 Pointssubject = "Treehouse loves + Margaret"
Margaret Maginnis
199 PointsI feel like a blockhead! once more
name = "Margaret" subject = "Treehouse loves" print (subject + name)
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsEverything that's inside the quotation marks will end up as part of the string of characters that's inside the variable. The whitespace (aka spaces) outside of the quotation marks will not end up inside the variable.
So you have this variable:
name = "margaret"
If you concatenate (chain, add, attach) them together with the string "Treehouse loves" you're going to end up with the string "Treehouse lovesmargaret" because there is no space at the end of "Treehouse loves" or at the beginning of "margaret". So what you need to do is add a space into "Treehouse loves_" there where I put the underscore should be a SPACE. So the whole expression would look like this:
subject = "Treehouse loves " + name
Don't worry, once you get it, you won't forget it :)
Margaret Maginnis
199 PointsI sure won't So... it's name = "Margaret" subject = "treehouse loves " + name
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsYes, that should do it.
Margaret Maginnis
199 Pointsnow I'm tripping up on the next challenge .format Great! I really need to look at a reference book but then I won't learn it so well as this is so tedious it's painful.
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsJust keep asking questions when you run into a road block.
Margaret Maginnis
199 PointsI will prevail!
Margaret Maginnis
199 PointsMargaret Maginnis
199 PointsI don't get it. Don't I have enough spaces in there? I added an extra space on both sides of the subject. So, should it be
strings.py name = "margaret" subject = "Treehouse loves" + name