Lesson 26 of 34

String Methods: split, join, replace

9 min 30 XP

split() turns a sentence into a list of words. join() turns a list back into one string.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

strip() removes spaces at both ends, replace() swaps text, find() gives the position (-1 if missing) and count() counts occurrences.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

isdigit() and isalpha() tell you what a string is made of. [::-1] reverses a string.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Challenge

+30 XP

Read a sentence with input(). Capitalise the first letter of each word and print the words in reverse order. Example: "i love python" → "Python Love I"

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.