Python program to convert a list to string

Python program to convert a list to String :

In this example, we will learn how to convert a list to string. To achieve this, we will use join method of String. join is defined as below :

str.join(iterable)

The iterable passed to the join method should contain only string values. If it contains any non-string value, it will throw one TypeError. The value str is the separator string, i.e. the string that will be used to separate each element of the iterable. Let’s take a look into the program :

Python program :

The example programs are available here.

python convert list to string

Output :

one two three four five six

Let’s try by changing the separator to ‘,’.

python convert list to string

Output is :

one,two,three,four,five,six

Now, if we change one item of the list to an integer, it will produce the following output :

python list to string

check more on python doc

Leave a Reply