Lesson 10: split & join + mini-project
Two methods that bridge strings and lists: .split() breaks a string into a list of parts (e.g. by spaces or a comma), and .join() joins a list of strings back into one string with a separator. With them we'll build a small mini-project that counts the words in a sentence.
split is cutting a sausage string into pieces (a list); join is threading beads back onto a string into one piece.
- .split()
- Splits a string into a list of parts by a separator (default: whitespace).
- .join()
- Joins a list of strings into one string, with the separator written before join.
- word count
- How many words a text has; obtained from len of the split result.