Categories
Python Answers

How to make a comma-separated string from a list of strings in Python?

Spread the love

Sometimes, we want to make a comma-separated string from a list of strings in Python.

In this article, we’ll look at how to make a comma-separated string from a list of strings in Python.

How to make a comma-separated string from a list of strings in Python?

To make a comma-separated string from a list of strings in Python, we can use the string’s join method.

For instance, we write:

my_list = ['a', 'b', 'c', 'd']
my_string = ','.join(my_list)
print(my_string)

We call ''.join with my_list to join each entry in my_list with commas.

Therefore, my_string is 'a,b,c,d'.

Conclusion

To make a comma-separated string from a list of strings in Python, we can use the string’s join method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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