Student Handbook

Student Handbook

Open in ChatGPT
Ask ChatGPT about this page
Open in Claude
Ask Claude about this page

str.join

Joins a list of strings into one string.

Synopsis

separator.join(list)

Description

The string before the dot goes between the items. join is the opposite of split.

Parameters

Name Meaning
list A list of strings.

Return value

A str.

Example

colours = ["red", "green", "blue"]
print(", ".join(colours))
print("".join(["a", "b", "c"]))
print("-".join("abc"))

It prints:

red, green, blue
abc
a-b-c

Common mistake

print(", ".join([1, 2, 3]))

Python stops with:

TypeError: sequence item 0: expected str instance, int found

Every item must be a string. Store them as strings (["1", "2", "3"]), or build the text with an f-string.

See also

str.split, sum

str.join in the Python documentation

Last updated 2 weeks ago