Table of Contents
In this post, we will see how to convert a list to String in Python.
You can simply use string’s join method to convert a list to String in Python.
String’s join method
string’s join method return string in which element of the sequence is joined by separator.
1 2 3 |
sep.join(sequence) |
Let’s see some examples.
Join all the strings in list without any separator
1 2 3 4 |
listOfChars = ["a" , "b", "c", "d", "e"] ''.join(listOfChars) |
Output:
‘abcde’
Join all strings in list with space
1 2 3 4 |
listOfWords=["Hello", "world", "from", "java2blog"] ' '.join(listOfWords) |
Output:
‘Hello world from java2blog’
Join all the strings in list with comma
1 2 3 4 5 |
listOfCountries=["India", "China", "Nepal", "France"] countries_str=','.join(listOfCountries) print(countries_str) |
Output:
HIndia,China,Nepal,France
Convert list of ints to string in python
If you have list of ints, you can convert each item to string using map function.
1 2 3 4 5 |
list1 = [1, 2, 3, 4] str1 = ''.join(map(str, list1)) print(str1) |
Output:
1234
That’s all about Python convert list to String.
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.