strings.join

Program to join a list of strings with a separator

Functions

join(→ str)

Joins a list of strings using a separator

Module Contents

strings.join.join(separator: str, separated: list[str]) str

Joins a list of strings using a separator and returns the result.

Parameters:
  • separator – Separator to be used for joining the strings.

  • separated – List of strings to be joined.

Returns:

Joined string with the specified separator.

Examples:

>>> join("", ["a", "b", "c", "d"])
'abcd'
>>> join("#", ["a", "b", "c", "d"])
'a#b#c#d'
>>> join("#", "a")
'a'
>>> join(" ", ["You", "are", "amazing!"])
'You are amazing!'

This example should raise an exception for non-string elements: >>> join(“#”, [“a”, “b”, “c”, 1]) Traceback (most recent call last):

Exception: join() accepts only strings

Additional test case with a different separator: >>> join(“-”, [“apple”, “banana”, “cherry”]) ‘apple-banana-cherry’