Difference between str.capitalize() VS str.title() - GeeksforGeeks

11 Nov, 2021
Both title() and capitalize() have similar functionality of capitalizing first characters. Let us see the difference between the two of them.
title() function in Python is the Python String Method which is used to convert the first character in each word to Uppercase and remaining characters to Lowercase in the string and returns a new string.
Syntax: str.title()
Parameters: None
Returns: This function returns a string which has first letter in each word is uppercase and all remaining letters are lowercase. 
Example:
Python3
# Python Title() Method Example str1 = 'geeKs foR geEks'str2 = str1.title()print('First Output after Title() method is = ', str2) # observe the original stringprint('Converted String is = ', str1.title())print('Original String is = ', str1) # Performing title() function directlystr3 = 'ASIPU pawan kuMAr'.title()print('Second Output after Title() method is = ', str3) str4 = 'stutya kUMari sHAW'.title()print('Third Output after Title() method is = ', str4) str5 = '6041'.title()print('Fourth Output after Title() method is = ', str5)
Output:
First Output after Title() method is =  Geeks For Geeks
Converted String is =  Geeks For Geeks
Original String is =  geeKs foR geEks
Second Output after Title() method is =  Asipu Pawan Kumar
Third Output after Title() method is =  Stutya Kumari Shaw
Fourth Output after Title() method is =  6041
In Python, the capitalize() method converts the first character of a string to a capital (uppercase) letter. If the string has its first character as capital, then it returns the original string.
Syntax: str.capitalize()
Parameters: None
Returns: This function returns a string which has the first letter in uppercase and all remaining letters in lowercase. 
Example:
Python3
# Python program to demonstrate the# use of capitalize() function # capitalize() first letter of# string.name = "geeks for geeks" print(name.capitalize()) # demonstration of individual words# capitalization to generate camel casename1 = "geeks"name2 = "for"name3 = "geeks"print(name1.capitalize() + name2.capitalize()                         + name3.capitalize())
Output:
Geeks for geeks
GeeksForGeeks
The difference between them is that Python string method title() returns a copy of the string in which the first characters of all the words are capitalized whereas the string method capitalize() returns a copy of the string in which just the first word of the entire string is capitalized.
Example: 
str = "geeks for geeks"
str.title() will return Geeks For Geeks
str.capitalize() will return Geeks for geeks
Python3
str1 = "my name is xyz"str2 = "geeks for geeks" # using title()print(str1.title())print(str2.title()) # using capitalize()print(str1.capitalize())print(str2.capitalize())
Output:
My Name Is Xyz
Geeks For Geeks
My name is xyz
Geeks for geeks
lsheree1
abhishek0719kadiyan
python-string
Python-string-functions
Difference Between
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between var, let and const keywords in JavaScript
Difference Between Method Overloading and Method Overriding in Java
Difference between Prim's and Kruskal's algorithm for MST
Difference between Internal and External fragmentation
Difference between Compile-time and Run-time Polymorphism in Java
Read JSON file using Python
Adding new column to existing DataFrame in Pandas
Python map() function
How to get column names in Pandas dataframe