intermediate
Capitalize Words
Capitalize the first letter of each word.
Learn string methods for word manipulation.
📚 Concepts & Theory
Title Case
text.title() # Built-in 🎯 Your Challenge
Write capitalize_words without title().
📝 Starter Code
Python
def capitalize_words(text):
pass
print(capitalize_words('hello world'))
Solution
Python
def capitalize_words(text):
words = text.split()
result = []
for word in words:
result.append(word[0].upper() + word[1:])
return ' '.join(result)
print(capitalize_words('hello world'))
Explanation
Split, capitalize first char, join.
❓ Frequently Asked Questions
str.title()