In this post we will be joining the contents of a list in to a single string, in other words we will concatenate all items together. Lists in Python provide a means to store multiple pieces of data into a single variable. To do this we will be using the ‘join()’ method and it is important to note that this will only work with a list of strings.
See the below list which we will be using for this example.
List = ["Hello", "how", "are", "you", "today?"]
See the snippet of code below where we join the items in the list together along with a separator in between each item.
string = ' '.join(List) print(string)
The above would output the following as a result.
Hello how are you today? >>>