Python Program to Convert List To String

Write a Python program to convert a list to a string. In this programming language, we can use the join method to join or convert the list to a string.

strlist = ["Kiwi", "USA", "UK", "India", "Japan"]

str1 = ' '
str1 = str1.join(strlist)
print(str1)
Python Program to Convert List To String

Convert list to string using list comprehension.

strlist = ["Learn", "Programming", "From", "Tutorial", "Gateway"]

str1 = ' '.join([str(word) for word in strlist])
print(str1)
Learn Programming From Tutorial Gateway

Convert list to string using join and map function. 

strlist = ["Learn", "From", "Tutorial", "Gateway"]

str1 = ' '.join(map(str, strlist))
print(str1)
Learn From Tutorial Gateway

In this example, the for loop iterates the items and adds them to empty str. 

def listToString(strlist):
    str1 = ''

    for word in strlist:
        str1 = str1 + word + ' ' 

    return str1
        
strlist = ["Py", "Programs", "From", "Tutorial", "Gateway"]

print(listToString(strlist))
Py Programs From Tutorial Gateway 

In this Python example, we have shown all the possibilities for converting a list to a string. 

def listToString(strlist):
    str1 = ''

    for word in strlist:
        str1 = str1 + word + ' ' 

    return str1

strlist = ["Learn", "Program", "From", "Tutorial", "Gateway"]

str1 = ' '
str1 = str1.join(strlist)
print("join method output        = ", str1)

str2 = ' '.join([str(word) for word in strlist])
print("List Comprehension output = ", str2)

str3 = ' '.join(map(str, strlist))
print("map output                = ", str3)

print("Custom Function output    = ", listToString(strlist))
join method output        =  Learn Programs From Tutorial Gateway
List Comprehension output =  Learn Programs From Tutorial Gateway
map output                =  Learn Programs From Tutorial Gateway
Custom Function output    =  Learn Programs From Tutorial Gateway 

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.