Python capitalize the first letter of a sentence | Example code

Use Python built-in capitalize() method to capitalize the first letter of a sentence and change the rest of the characters into lowercase.

This method is used on string data in various ways without just capitalizing on the first characters.


sentence .capitalize()

Example of capitalizing the first letter of every sentence in Python

The capitalize() doesn’t take any argument and returns a new string after modifying. It doesn’t change the original string sentence.

For example, a sentence starts with the lowercase letter and contains one word with the first uppercase letter.

myString = 'welcome to Python programing'

# Convert the string by capitalize method
new_str = myString.capitalize()

print(new_str)

Output:

Python capitalize the first letter of a sentence

Do comment if you have any doubts and suggestions on this Python capitalize code.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.