Python, Capitalize First Letter In A Sentence


How to capitalize first letter of first word in a sentence using Python?

Method 1: Using Upper

The logic is simple. Take the first letter of the sentence, make it upper and join it to the rest of the sentence.

Python 3.8.0
>>> str = "it's hello word way to go"
>>> "".join([str[0].upper(),str[1:]])
"It's hello word way to go"

Method 2: Using Capitalize

Python has a built in method which can be used to capitalize the first letter of the sentence.

Python 3.8.0
>>> "it's hello world good old hay way. Hello".capitalize()
"It's hello world good old hay way. hello"