Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

Capitalize First Letter of Each Word

Apply title casing to entered text. Students inspect uppercased starts, lowercased remaining letters, and why title is not simply a first-letter-only operation.

IntermediatePhase 5 - Category 3: Word OperationsExample 6 of 10
capitalize-first-letter-of-each-word.py
1# Take string input
2s = input("Enter a string: ")
3
4# Capitalize first letter of each word
5result = s.title()
6print(f"Capitalized: {result}")

Output

Enter a string: hello world
Capitalized: Hello World

In this one

  • Apply title-case mappings
  • Understand inner-case changes
  • Recognize word-boundary rules

How it works

  1. 1

    Read the response unchanged.

  2. 2

    Create result with s.title().

  3. 3

    Print the returned title-cased text.

Edge cases

Does the method keep inner uppercase letters?

Does the method keep inner uppercase letters?

No. Following cased letters are generally lowercased.

Does empty input work?

Does empty input work?

Yes. The result is empty.

What's going on

s.title() returns title-cased text. It typically uppercases the start of each cased word segment and lowercases the following cased letters.

Thus hELLO becomes Hello, not HELLO. The method has its own word-boundary rules, including surprising apostrophe behavior, so it is not a grammar-aware title editor. Unlike split and join, it does not intentionally normalize all whitespace separators.

Does the method keep inner uppercase letters? No. Following cased letters are generally lowercased.

Does empty input work? Yes. The result is empty.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

What does hELLO become?

Pick an answer to check it.

Question 2

Does the method keep inner uppercase letters?

Pick an answer to check it.

Questions people ask

Does the method keep inner uppercase letters?

No. Following cased letters are generally lowercased.

Does empty input work?

Yes. The result is empty.

What does hELLO become?

Hello.