List to string conversion in python by R4R Team

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).
Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!