Sponsored Reserved space — layout preview until AdSense is connected

Split and join words

Turn a sentence into tokens, then rebuild it with a custom separator.

10 lines 5 views 0 copies Updated May 23, 2026
Try in editor

How it works

str.split() breaks text on whitespace by default. Pass a delimiter to split on commas, pipes, or any character.

str.join() is the inverse: call it on the separator string and pass an iterable of pieces.

Together they are perfect for parsing simple CSV-like input without importing the csv module.

Python
Try in editor
raw = "python split join example"
words = raw.split()
print(words)

joined = "-".join(words)
print(joined)

csv_line = "red,green,blue"
colors = csv_line.split(",")
print(" | ".join(colors))

Sponsored

Sponsored Reserved space — layout preview until AdSense is connected

Run this sample

Open the browser IDE to tweak the example and see results without installing anything.

Open editor

More from Strings & text