Skip to main content
Lists

How to convert a list to a string in Python

Quick answer

Use ''.join(lst) if the elements are strings. For other types, wrap with map(str, ...).

words = ["hello", "world", "python"]
result = " ".join(words)
print(result)  # 'hello world python'

str.join(iterable) is the idiomatic way. The string you call it on is the separator β€” ' '.join for spaces, ','.join for CSV-style, ''.join for no separator at all.

Every element in the iterable must already be a string. If you have numbers or other types, map them through str first: ', '.join(str(n) for n in [1, 2, 3]). Trying to join a list containing an int raises TypeError.

Do NOT use str(lst) β€” that produces the Python repr with square brackets and quotes ('[1, 2, 3]'), which is rarely what you want. It's fine for debug printing but not for building output text.

Variations

Join numbers

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

Generator expression is enough β€” no need to build an intermediate list.

Just get repr(list)

nums = [1, 2, 3]
print(str(nums))  # '[1, 2, 3]'

For debug only β€” keeps the brackets and commas.

Join with a newline (multi-line)

lines = ["first", "second", "third"]
print("\n".join(lines))

Common for building console output or file contents.

Practise this in your browser

Every how-to has a live lesson. Free tier, no card.

Start free β†’

Unlock every lesson

Pro β€” $12/mo, unlimited AI, cancel any time.

See Pro plans β†’

Get one Python lesson + one career idea every Friday

No spam, no "buy our course now". Three bullets, every Friday. Unsubscribe with one click.

Related how-tos