Capitalize First Letter of Each Word in Python

Capitalize the first letter of each word in a sentence.

BeginnerString ProgramsExample 11 of 25
capitalize-first-letter-of-each-word.py
1# Program to capitalize first letter of each word
2
3s = input("Enter a sentence: ")
4
5result = s.title()
6
7print("Title case:", result)

Output

Enter a sentence: hello world
Title case: Hello World

What's going on

We use .title() which capitalizes the first character of each word and lowercases the rest.

After this program

If the idea is still fuzzy, read Day 4: Strings and String Methods in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 25 string programs, or see every topic on Python exercises.