The capitalize method
The capitalize method returns a string with the first character in uppercase, while all other characters will be lowercase.
Syntax
string.capitalize()
Example
Let's apply the capitalize method to the following line:
txt = 'abcde'
print(txt.capitalize())
Result of code execution:
'Abcde'
Example
Let's compare the application of the capitalize method and the title method:
txt = 'abc def'
print(txt.capitalize())
print(txt.title())
Result of code execution:
'Abc def'
'Abc Def'
See also
-
method
title,
which changes the first character of each word to uppercase -
method
upper,
which returns all characters of a string in uppercase -
method
isupper,
which checks all characters in a string for uppercase -
method
lower,
which returns all lowercase characters -
method
swapcase,
which changes the case of characters to the opposite