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.