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.
The syntax of
capitalize() method is:
capitalize() function does not take any parameters.
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" print(text1.capitalize()) # Converts the first character to Uppercase/title case # keeps rest in lowercase text2= "pYTHON Is FUN" print(text2.capitalize()) # In case of diagraph the first letter is capitalized text3= "ß" print(text3.capitalize()) # In case of non alphabets text4= "*disclaimer" print(text4.capitalize())
Python programming Python is fun Ss *disclaimer