The split Method: Breaking Strings into Lists
join is a string method that reverses split by combining list elements into a single string with a specified delimiter.
From Separate Pieces to One String
A list can hold several separate strings, while a final message, label, or formatted line often needs to be one string. The join method connects those separate elements into a single string. It is described as reversing split: split breaks a string into list elements, while join combines list elements into a string using a delimiter.
The delimiter is inserted only between neighboring elements. It does not appear before the first element or after the last element.
The Joining Mechanism
The general form is delimiter.join(list). The delimiter is the string that controls what appears between the list elements. The list is the sequence whose elements are combined. This arrangement can feel backward at first because the method is not written after the list. join is a string method, so it is invoked on the delimiter string, and the list is passed as the method argument.
Learning Python is usefulHere, the delimiter is a single space string. The four list elements remain in their original order, and a space is placed between each adjacent pair. There is no extra space at the beginning or end.
Tracing Delimiters Through the Result
Building a Sentence
Combine the list ["Learning", "Python", "is", "useful"] into one string with spaces between the words.
Choose the delimiter: Use a single space string because the desired result needs spaces between words.
Invoke join: Write the delimiter first and call join with the list: " ".join(words).
Place the delimiter: Insert one space between Learning and Python, Python and is, and is and useful.
Leave the boundaries alone: Do not place a space before Learning or after useful.
Learning Python is useful
What do you think happens?
What will the result be when the same list is joined with an empty string as the delimiter?
Reveal answer
Answer: LearningPythonisuseful
An empty string contributes no characters between elements, so the elements are concatenated directly.
PythonAn empty string is still a delimiter; it simply contributes nothing between elements. This makes it useful when individual characters should become a word or when string fragments should be merged without visible separators.
Choosing a Useful Separator
The delimiter determines the format of the final string without changing the list elements themselves. A space creates readable word-like text, an empty string creates direct concatenation, and a custom string can make boundaries visible for a particular purpose. The same sequence can therefore produce different output simply by changing the string on which join is called.
home/projects/python
Ada,Lovelace,1815In the first example, the slash becomes the visible boundary between the path parts. In the second, the comma separates the fields in a row-like string. In both cases, join follows the same pattern: delimiter.join(list). The practical decision is which separator makes the intended structure clear.
Mistakes with Method Placement
Calling join on the list instead of on the delimiter.
join is a string method invoked on the delimiter string. The list is passed to join as its argument.
Fix:
" ".join(words)Expecting the delimiter at the beginning or end.
The delimiter appears only between elements.
Fix:
The result is "red, green", not ", red, green, ".Using a visible delimiter when no separator is wanted.
A comma is deliberately inserted between every pair of adjacent elements.
Fix:
Use "".join(["P", "y", "t", "h", "o", "n"]) when the characters should be merged directly.
Practice with Custom Formats
Given the list ["2026", "09", "27"], choose a delimiter and write a join expression that produces the string 2026-09-27.
Hints
- The desired separator is a hyphen.
- Place the delimiter before .join.
- Pass the list to join.
Given the list ["clean", "simple", "clear"], write two join expressions: one that produces clean simple clear and one that produces clean | simple | clear.
Hints
- Use a single space for the first result.
- For the second result, the delimiter must include a space on both sides of the vertical bar.
Checking a Custom Separator
Combine ["clean", "simple", "clear"] into clean | simple | clear.
Identify the repeated boundary: The text between each pair is space, vertical bar, space.
Use that text as the delimiter: The delimiter is " | ".
Pass the list: Apply the delimiter with " | ".join(["clean", "simple", "clear"]).
clean | simple | clear
Essential Takeaways
- join combines list elements into one string and conceptually reverses split.
- The syntax is delimiter.join(list).
- join is invoked on the delimiter string, not on the list.
- The delimiter appears only between elements.
- An empty string delimiter concatenates elements with no separator.
- Changing the delimiter changes the final format while leaving the list order intact.
Key Takeaways
- The join method transforms separate list strings into one string.
- The delimiter controls what appears between adjacent elements.
- The delimiter receives the join method, and the list is passed as its argument.
- An empty string joins elements directly with no visible separator.
- Custom delimiters make join useful for sentences, paths, rows, and other formatted strings.