Skip to content

Python capitalize the first letter of a sentence | Example code

  • by

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()



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.3.3 (Community Edition)

Windows 10

Python 3.10.1

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

Leave a Reply

Your email address will not be published. Required fields are marked *