Working with text
Strings have many built-in methods. They never change the original string; they return a new one.
s = " Hello, Harare "
s.strip() # "Hello, Harare" remove spaces at both ends
s.lower() # " hello, harare "
s.upper() # " HELLO, HARARE "
s.replace("H", "J") # " Jello, Jarare "
"harare".capitalize() # "Harare"
"Harare" in s # True
s.count("a") # 3
Indexing and slicing
Strings can be indexed and sliced just like lists:
word = "Python"
word[0] # "P"
word[-1] # "n"
word[1:4] # "yth"
word[::-1] # "nohtyP" a step of -1 reverses
split and join
"a b c".split() # ["a", "b", "c"] splits on any spaces
"2026-11-16".split("-") # ["2026", "11", "16"]
"-".join(["a", "b", "c"]) # "a-b-c"
Multiplying a string repeats it: "ab" * 3 is "ababab".
Your task
clean_name(raw): remove extra spaces and give each word one capital letter." tARIRO moyo "becomes"Tariro Moyo".is_palindrome(text):Trueif the text reads the same backwards, ignoring case and spaces.mask_phone(number): replace every digit except the last 3 with*.