Today we’ll be talking about joining strings. We can join strings using the method join.
The method join(seq) takes the string elements from a sequence and concatenates them using the string as the separator. Here’s how we can use it with a string:
>>> separator = " <*> "
>>> sequence = "star" # with a string
>>> separator.join(sequence)
's <*> t <*> a <*> r'
And here’s how it works with a list:
>>> separator = "-"
>>> print(separator.join(["one", "two", "three"])) # with a list
one-two-three
and with a tuple:
>>> print(" and ".join(("one", "two", "three", "go"))) # with a tuple
one and two and three and go
Here’s the video version of the article: