Python String capitalize() method converts the first character of a string to the capital (uppercase) letter and make all other characters in the string lowercase. If the String has its first character as capital, then it returns the original String.
Syntax
string.capitalize()
Parameters
This method doesn’t contain any parameters.
Return Value
It returns a string that has its first character as capital.
Visual Representation
Example 1: How does String capitalize() Method Work?
s1="hello my name is ankit"
print(s1.capitalize())
Output
Hello my name is ankit
Example 2: String contains digits or special characters
s1="789hello how are you?"
print(s1.capitalize())
Output
789hello how are you?
Example 3: An empty string
s1= " "
print(s1.capitalize())
Output
Ankit Lathiya is a Master of Computer Application by education and Android and Laravel Developer by profession and one of the authors of this blog. He is also expert in JavaScript and Python development.