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.
Kyle Curtis641 Points
Ways 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.
Steven Parker208,479 Points
Hi, 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.