Editor

Capitalize Words

Strings · Beginner · 35 XP · about 3 min

Write a function called capitalize_words(s) that capitalizes the first letter of each word in a string.

Example

capitalize_words("hello world")       # Returns "Hello World"
capitalize_words("python is fun")     # Returns "Python Is Fun"
capitalize_words("THE QUICK BROWN")   # Returns "The Quick Brown"

Requirements

  • Capitalize the first letter of each word
  • Convert all other letters to lowercase
  • Words are separated by spaces
def capitalize_words(s):
# Your code here
pass
# Test your function
print(capitalize_words("hello world"))
print(capitalize_words("python is fun"))

Ready?

Accept the challenge to start writing. A small timer counts the time this page is in view.

Output appears here.