You are here: Home / Topics / List to string conversion in python

List to string conversion in python

Filed under: Python on 2022-08-26 13:26:46

String and list both are the different data type of different domain and structure of both data type is different. So when we want to convert list to string, we must aware of string as well as list in python.

Example of conversion- 

List=['Hello','String']
And we want to make a string which is look like - 
S='HelloString'

Program -

l=['Hello','String']
s=str(l)
print(s)
s=''.join(l)
print(s)
s='-'.join(l)
print(s)
s='-Between-'.join(l)
print(s)

Output - 

['Hello', 'String']
HelloString
Hello-String
Hello-Between-String

In this program for conversing the list to the string , we use join to combine the all items in a list and add them and create a string and in join() we can also add our string which we want to add like -.join(list).


About Author:
Y
Yogesh     View Profile
I am Yogesh Sharma. I found this website very useful for all the students. It is a very good website for learning thousands of multiple choice questions. Basically it is like a community website. Everyone can add questions so am I. I will add mcqs in this website to help you.