Splitting & Joining Text1 / 4
CRASH COURSE
Splitting & Joining Text
split() cuts a string into a list. With no argument it splits on whitespace; with an argument it splits on that separator.
- join() does the reverse. The separator comes first: ", ".join(items) glues the items together with a comma and a space.
- Strings are immutable, so methods like replace() return a new string instead of changing the original.
words = "learn python today".split()
print(len(words))
print("-".join(words))