Python String capitalize()

Filed Under: Python String

Python String capitalize() function returns the capitalized version of the string. The first character of the returned string is converted to uppercase and rest of the characters are changed to lowercase.

Python String capitalize()

Let’s look at an example of string capitalize() function.

s = 'WelCome to JournalDev'


Output: Welcome to journaldev

python string capitalize

Let’s look at another example where string first character is not an ASCII character.

s = '歡迎'  # welcome in Chinese

s = 'çA†'



python string capitalize special characters

The Chinese capitalized version looks same as the original string. But I don’t know the Chinese language, so I am not sure if it’s correct or not.

For the special character, it looks like the capitalization worked and the first character got changed to uppercase.

Finally, let’s look at an example of getting user input and capitalize the input string and print it.

s = input('Please enter a string:\n')

print('Input String Capitalized Version:\n', s.capitalize())

python string capetalize user input

>>> s = input('Please enter a string:\n')
Please enter a string:
apple çdžˇƒÏ
>>> print('Input String Capitalized Version:\n', s.capitalize())
Input String Capitalized Version:
 Apple ç熡ƒï
You can checkout complete python script and more Python examples from our GitHub Repository.

Reference: Official Documentation

Leave a Reply

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

Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages