How to convert a list to a string with join()

1 min

Elements of a list can be concatenated to string with the join() method.

Every element of a list passed to the join() method will be concatenated to form a string separated by our initial string.

Let me show you with code

my_words = ["Hello", "Everyone", "I'm", "Garry"]

sentence = " ".join(my_words)

print(sentence)
It will print out a string that contains all elements of the list
my_groceries_list = ["Apples", "Carrots", "Butter", "Milks"]

my_groceries = ",".join(my_groceries_list)

print(my_groceries)
This time with a comma.

Here you are! You now know how to convert a list to a string with join().

More on fundamentals

If you want to know more about Python fundamentals without headaches... check out the other articles I wrote by clicking just here:

Fundamentals - The Python You Need
We gathered the only Python essentials that you will probably ever need.