How to Use String capitalize() Method in PythonPython Basics


The capitalize() function turns the first letter of the string to uppercase and the other letters to lowercase.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

str = "she is good at Math"
print (str.capitalize())

str = " she likes watching TV"
print (str.capitalize())

Output:

She is good at math
 she likes watching tv

Syntax

str.capitalize()

Parameters

The method doesn’t take any parameters.

Return Value

It returns a string with the first letter capitalized and all other characters lowercased.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us