"Intermediate Swift" was retired on May 31, 2020.

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

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

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.

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