Python – How to convert a list to a string

There must be already a gazillion articles about how to do this, but one more won’t hurt.

Suppose you have the a list as the following:

In [2]: alist
Out[2]: ['apple', 'banana', 'pear']

To create a string from “alist” with a comma separator, we can do this:

In [3]: ','.join(alist)
Out[3]: 'apple,banana,pear'

Basically, you can place a desired separator in the ”, or omit it totally.


Leave a Reply

Your email address will not be published. Required fields are marked *