.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:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Skill path
Analyze Data with Python
Learn to analyze and visualize data using Python and statistics.Includes 8 CoursesWith CertificateIntermediate13 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours