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

George Lugo
seal-mask
.a{fill-rule:evenodd;}techdegree
George Lugo
Python Web Development Techdegree Student 922 Points

why doesn't subject work for subject = "Treehouse loves" + name

it says i need extra space but you shouldn't as this code should be right

strings.py
name = """George"""

subject  = "Treehouse loves" +  name

2 Answers

andren
andren
28,538 Points

The output of printing subject would be Treehouse lovesGeorge, as you probably notice it does indeed lack proper spacing.

When you use string concatentaion strings are glued together without any spaces added between them, if you want there to be a space you have to add one manually. This can be done either by adding a space to one of the string like this:

subject = "Treehouse loves " + name

Or by concatenating a string that just contains a space like this:

subject = "Treehouse loves" + " " + name

Either way will work, but one way or the other you do have to add a space manually.

George Lugo
seal-mask
.a{fill-rule:evenodd;}techdegree
George Lugo
Python Web Development Techdegree Student 922 Points

name = "george"

subject = "Treehouse loves {} + " print (subject.format(name))

I was also trying this format why doesn't this method work if i may ask