User Tools

Site Tools


python:join

How to use join to merge substrings into a string

If you have one list of strings, for example list = [“orange”, “banana”, “apple”] and you want them into a single string, just use join :

>>> list = ["orange", "banana", "apple"]
>>> print list
['orange', 'banana', 'apple']
>>> str = ";".join(list)
>>> print str
orange;banana;apple
>>>
>>> str = "_".join(list)
>>> print str
orange_banana_apple
>>>
>>> str = "XXX".join(list)
>>> print str
orangeXXXbananaXXXapple

python/join.txt · Last modified: 2013/03/16 17:41 (external edit)