In this article we will discuss how to convert a list to string.

string’s join() in python:

Python string class provides a member function join() i.e.

It joins all the elements in iterable sequence by separator_string. We will use this to convert list to a string

Converting list of strings to a string using str.join()

Suppose we have a list of strings,

Now, join all the strings in list with a white space as separator i.e.

It returned followings string i.e.

Let’s try an another separator and join the elements in list by ‘,’ and create a string i.e.

It returned followings string i.e.

Converting list of ints to a string using str.join()

Suppose we have a list that contains some numbers (ints) too i.e.

We cannot cannot call string’s join() function on this list directly. We need to convert this to complete list strings only and then only we should call join() on this new list i.e.

String returned will be.

Complete example is as follows,

Output:

 

Click Here to Subscribe for more Articles / Tutorials like this.