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 Parker200,698 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.