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
Run in browser1# Program to capitalize first letter of each word23s = input("Enter a sentence: ")45result = s.title()67print("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.