Why we concatenating string by +?


print 'hello '+'world' and print 'hello ''world'
both are available.


Two string literals next to each other without any operator will be read as a single string, they don't get concatenated, it's be a single string as soon as the code is read (before it is run)

So it's just a syntax feature.

If you actually needed to concatenate two strings, then you would need + (or equivalent).

For example, this isn't going to work:

string1 = 'hello '
string2 = 'world!'

print(string1 string2)


hi!thank you for your reply.do you means this code:print 'hello ''world' is a single string in python?If I work on two string should be concatenated them by+?Looking forward to your reply´╝îthank you!


@lilei007 Yup you got that correct.


Thank you very much! :grinning: