Join a list of strings

words = ["learn", "python", "today"]
sentence = " ".join(words)
print(sentence)   # learn python today

The separator goes before join, and the list goes inside the parentheses. Use "" for no separator or ", " for a comma-separated list.

Join a list of numbers

numbers = [1, 2, 3]
result = ", ".join(str(n) for n in numbers)
print(result)   # 1, 2, 3

join only accepts strings, so convert each number with str first using a generator expression.

Turn a list into its literal text form

items = ["a", "b", "c"]
text = str(items)
print(text)   # ["a", "b", "c"]

When you want the bracketed Python representation rather than joined values, plain str() does the job.

Which method should you use?

  • str.join — the right choice for building readable text from list items.
  • join with str() — when the list holds numbers or other non-strings.
  • str(list) — when you want the literal list representation for debugging.
  • Common mistake: calling join on a list with non-string items, which raises a TypeError.

Frequently asked questions

Why do I get a TypeError when joining?

Because the list contains non-string items. Convert them first, for example "".join(str(x) for x in items).

How do I join with each item on its own line?

Use a newline as the separator: " ".join(items) puts each element on a separate line.

Strings and lists are core skills — sharpen them in our free Python course.