Python String capitalize() Method
Example
Upper case the first letter in this sentence:
txt = "hello, and welcome to my world."
x = txt.capitalize()
print (x)
Try it Yourself »
Definition and Usage
The capitalize()
method returns a string
where the first character is upper case, and the rest is lower case.
Syntax
string.capitalize()
Parameter Values
No parameters
More Examples
Example
The first character is converted to upper case, and the rest are converted to lower case:
txt = "python
is FUN!"
x = txt.capitalize()
print (x)
Try it Yourself »
Example
See what happens if the first character is a number:
txt = "36 is my age."
x = txt.capitalize()
print (x)
Try it Yourself »