Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

str.join

Places the separator between successive strings from an iterable.

Version: Python 3.14; repository image, production runtime not attested

Syntax

separator.join(iterable_of_strings)

Places the separator between successive strings from an iterable.

An empty input yields an empty string. Empty elements still occupy a position between separators.

The method is called on the separator rather than the collection. The empty string between a and c occupies a real position, giving two consecutive separators. Non-string members raise TypeError; no members produce an empty string.

assert ",".join(iter(["", "x", ""])) == ",x,"

Examples

print("|".join(["a", "", "c"]))
print(repr("|".join([])))

Result

a||c
''

The method is called on the separator rather than the collection. The empty string between a and c occupies a real position, giving two consecutive separators. Non-string members raise TypeError; no members produce an empty string.

Sources