Python String capitalize()

Python string capitalize() method will convert the first letter in a string to uppercase and keep the rest of the characters in lowercase. The capitalize() function does not modify the original string and instead returns a string copy.

capitalize() Syntax

The syntax of capitalize() method is:


capitalize() Parameter

The capitalize() function does not take any parameters.

Return Value from capitalize()

The capitalize() function returns a copy of the string with the first character capitalized and all other characters lowercased. It doesn’t modify the original string.

Note: In Python 3.8 onwards, the first character is converted into a title case rather than uppercase. It means that characters like digraphs will only have their first letter capitalized instead of the whole character.

Example: Capitalize a string in Python

# Converts the first character to Uppercase/title case
# keeps rest in lowercase
text1 = "python programming"

# Converts the first character to Uppercase/title case
# keeps rest in lowercase
text2= "pYTHON Is FUN"

# In case of diagraph the first letter is capitalized
text3= "ß"

# In case of non alphabets
text4= "*disclaimer"


Python programming
Python is fun
Leave a Reply

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

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.

You May Also Like
List of Python free ebooks

List of Free Python Books

Table of Contents Hide Python SuccinctlyPython Data Science HandbookThink Python 2nd EditionAutomate the Boring Stuff with PythonMaking Games with Python & PygameData Structures and Algorithms in Python Google Python Style GuideA…
View Post