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() print(res)
Let’s See what happens if the first character is a number:
txt = "100 is my age." res = txt.capitalize() print(res)
Output: 100 is my age.
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)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.