Home »
Python
Python String capitalize() Method
By IncludeHelp Last updated : December 15, 2024
Python String capitalize() Method
The capitalize() is an in-built method in Python, it returns the string in Capitalized case, in which first character of the sentence is in uppercase and rest of the characters are in lowercase.
Syntax
String.capitalize()
Parameters
None
Return Value
It returns capitalize case string.
Example 1
# str1
str1 = "Hello world, how are you?"
print(str1.capitalize())
# str2
str2 = "HELLO WORLD, HOW ARE YOU?"
print(str2.capitalize())
# str3
str3 = "hello world, how are you?"
print(str3.capitalize())
# str4
str4 = "100google is a website"
print(str4.capitalize())
Output
Hello world, how are you?
Hello world, how are you?
Hello world, how are you?
100google is a website
Example 2
str1 = "this is a test"
print(str1.capitalize())
str2 = "TESTING THE CAPITALIZE METHOD"
print(str2.capitalize())
str3 = "python programming"
print(str3.capitalize())
str4 = "123abc is a code"
print(str4.capitalize())
Output
This is a test
Testing the capitalize method
Python programming
123abc is a code