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 lowercase. 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.

Note: the capitalize() function only affects the first character of the string and converts the remaining characters to lowercase. If you want to capitalize specific words or manipulate strings in other ways, you might need to use other string methods or functions.

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 *