1. Concept library
  2. Python Foundations
  3. Module 6: Strings and formatting

Concept

Splitting and joining

split() breaks a string into a list on a separator; join() does the reverse. Between them they handle most line-based and comma-separated text.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain what split() returns and how the separator and its absence behave
  2. Parse a comma-separated line into fields and build a line back with join
  3. Spot why names.join(", ") fails and write the join the right way round

In practice

A few lines that show Splitting and joining doing its job.

Python
line = "ada,grace,linus"
names = line.split(",")
print(names)                       # ['ada', 'grace', 'linus']

print(" | ".join(names))
words = "  several   spaces here ".split()
print(words)                       # ['several', 'spaces', 'here']

The common mistake

Watch for

Calling names.join(", ") on the list. join is a string method: the separator comes first, as in ", ".join(names).

What to know first

Your roadmap puts these before Splitting and joining, unless you already know them.

How it stays learned

Once a session shows you understand Splitting and joining, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled
Previous in the module← f-strings