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 trialKyle Curtis
641 PointsWays to add spacing when adding strings
In the video "strings" in Learn Python, Kenneth adds strings together like this:
'Hello ' + 'there'
The spacing is after 'Hello' , which makes it so it's not one word like: 'Hellothere'. However I have also seen people write code like this:
'Hello' + ' ' + 'there'
The spacing is added as a string itself. Is this also a good way to add strings together? I know the way in the video requires less code but I was just wondering if this is a good alternative.
1 Answer
Steven Parker
231,236 PointsHi, I got alerted by your tag.
I would never concatenate literals in code, but just make a larger literal from them. So in this case, instead of either of the options shown, I would simply write: 'Hello there'.
I would use concatenation to join variables to literals or to each other.