Python (Fall 2026) Module 8-2: String Methods for Manipulation
Watch on YouTube →
Overview
Bill Moseley explains how Python's `str.split()` breaks text into a list, including how its separator and `maxsplit` arguments control the result. He builds a reusable `wordCount` function that returns 13 for an example sentence, then demonstrates `str.join()` to combine list elements using a chosen separator.
Key takeaways
- Python's `str.split()` with no arguments divides text on whitespace and returns a list suitable for further processing.
- A basic word counter can return `len(sentence.split())`; Moseley's example reports 13 words.
- The separator passed to `split()` is removed from the resulting pieces, while `maxsplit` limits how many divisions occur.
- When a requested separator is absent, `split()` returns the original text as a single list element.
- Python's `separator.join(iterable)` combines string elements with the chosen separator, such as joining words with `@` instead of spaces.
Chapters
0:00
Using `str.split()` to Count Words
- Calling `split()` without arguments separates a string on whitespace and produces a list of words.
- Taking the list's length gives a basic word count; the example sentence contains 13 words.
- Bill Moseley turns the approach into a reusable `wordCount(strSentence)` function that returns the count.
4:44
Controlling `split()` with Separators and `maxsplit`
- Passing a separator such as `"."` or `"E"` makes `split()` divide the string at that character.
- The separator is removed from the resulting pieces, so splitting on spaces leaves no spaces in the list.
- Using `maxsplit=2` limits the operation to two splits and leaves the remainder together in the final piece.
- If the separator does not occur in the string, `split()` leaves it unsplit.
7:19
Reassembling Text with `str.join()`
- The separator string calls `.join(iterable)` to combine list elements into one string.
- Moseley splits a sentence on spaces, then uses `"@".join(liText)` to place an at sign between the words.
- Choosing a different join separator can transform text, including replacing repeated separators after splitting.
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Bill Moseley, Ph.D. - Computer Science Educator.