Computer >> Computer tutorials >  >> Programming >> Python

How to do string concatenation without '+' operator in Python?


You can use str.join(list_of_strings) from the string class. The string you call it on is used to join the list of strings you provide as argument to it.

For example

>>> ' '.join(['Hello', 'World'])
'Hello World'
>>> ''.join(['Hello', 'World', 'People'])
'HelloWorldPeople'
>>> ', '.join(['Hello', 'World', 'People'])
'Hello, World, People'

Note that the string we call it on is inserted in between the list of strings we pass it as argument.