Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

string capitalize() in Python

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Python String capitalize() method returns a copy of the original string and converts the first character of the string to a capital (uppercase) letter, while making all other characters in the string lowercase letters.

Python String capitalize() Method Syntax

Syntax: string_name.capitalize()

Parameter:  The capitalize() function does not takes any parameter. 

Return: The capitalize() function returns a string with the first character in the capital.

Python String capitalize() Method Example

Python




name = "geeks FOR geeks"
 
print(name.capitalize())


Output:

Geeks for geeks

Example 1: capitalize() only capitalizes the first letter of a string and lowers all the remaining characters

Python3




string = "roses are red"
print("Original string:", string)
print("After using capitalzie:", string.capitalize())


Output:

Original string: roses are red
After using capitalzie: Roses are red

Example 2: Python String capitalize() Method Doesn’t Modify the Original String

Python String capitalize() Method creates and returns a copy of the original string after modifications.

Python3




string = "geeks for geeks"
string_2 = string.capitalize()
 
print("New string after using capitalize():", string_2)
 
print("Original string:", string)


Output:

New string after using capitalize(): Geeks for geeks
Original string: geeks for geeks

My Personal Notes arrow_drop_up
Last Updated : 18 Aug, 2022
Like Article
Save Article
Similar Reads
Related Tutorials