🔤 Working with Text, lesson 4 of 5
Splitting and joining
Break text into pieces with split() and glue pieces together with join().
8 min
2 exercises
2 quizzes
0/4 solved
Getting Python ready… examples can run in a moment.
text.split() cuts a string into a list of
words (a list is an ordered collection written in
[ ]; you'll explore lists fully in a later module).
With no argument it splits on any whitespace. Pass a
separator to split on something else:
"a,b,c".split(",").
Splitting
len() of a list counts its items. Write your own sentence and count its words.
What does this print?
join does the opposite: separator.join(pieces)
glues a list of strings together with the separator
between them. It looks backwards at first: the
separator comes first.
Joining
The last example turns a title into a URL-friendly "slug". Try your own title.
Word counter
Count the words in text and store the number in
count.
Date format
date uses slashes. Turn it into 2026-09-30 by
splitting on "/" and joining with "-". Store it
in iso.
What does this print?