The capitalize method

The capitalize method returns a string with the first character in uppercase, while all other characters will be lowercase.

Syntax

pythonstring.capitalize()

Example

Let's apply the capitalize method to the following line:

pythontxt = 'abcde'
print(txt.capitalize())

Result of code execution:

python'Abcde'

Example

Let's compare the application of the capitalize method and the title method:

pythontxt = 'abc def'
print(txt.capitalize())
print(txt.title())

Result of code execution:

python'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