Skip to content

How to capitalize the first letter in Python | Example code

  • by

Use capitalize() method If you want to capitalize the only first letter of a given sentence in Python. This method returns a copy of the original string and converts the first character of the string to capital and rest all other characters in the string lowercase letters.

Example capitalize the first letter in Python

Simple example code capitalizes the first letter only. If the first character is an integer, it will not capitalize the first letter.

txt = 'the brOwn Fox'

res = txt.capitalize()



How to capitalize the first letter in Python

Use title() function Capitalize the first letter of each word in a string in Python.

txt = 'the brOwn Fox'

res = txt.title()



The Brown Fox

Do comment if you have any doubts or suggestions on this Python capitalize topic.

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 *

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