Skip to content

Capitalize() function in Python | Example code

  • by

Python Capitalize() function is used to convert the first character in uppercase, and the rest is lower case. Actually, this method returns a copy of the original string with the first character of the string to a capital other characters in the string lowercase letters.


Note: It doesn’t modify the original string.

Example how to use Capitalize() function in Python

Simple example code Capitalize a Sentence.

s = "python Is beSt."

res = s.capitalize()



Capitalize() function in Python

Let’s See what happens if the first character is a number:

txt = "100 is my age."

res = txt.capitalize()


Output: 100 is my age.

Do comment if you have any doubts or suggestions on this Python function 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.