.capitalize()

Published May 10, 2021Updated Sep 22, 2023
Contribute to Docs

The .capitalize() method takes in a string, and returns a copy of the string with the first character in upper case, and the remaining characters in lower case.

Syntax

"string".capitalize()
  • This method does not have any parameters.
  • It does not modify the original string, it returns a copy of the string with the applicable case changes.

Example

The following example applies .capitalize() to a string in which all the characters are uppercase:

print("WELCOME TO CODECADEMY DOCS!".capitalize())

This will result in:

Welcome to codecademy docs!

Codebyte Example

The following example is runnable and uses the .capitalize() method:

Code
Output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy