Python capitalize() method
Description
Python capitalize() converts the first letter of a string to uppercase and all other letters to lowercase. For 8-bit byte encodings, this depends on the local environment.
Syntax
capitalize() method syntax:
str.capitalize()
Parameters
- none.
Return Value
This method returns a string with its first letter capitalized.
Example
The following example shows how to use the capitalize() method:
s
=
'
a, B
'
s
.
capitalize
(
)
'
A, b
'
s
=
'
a, B
'
a is preceded by a space
s
.
capitalize
(
)
'
a, b
'
s
=
'
a, BCD
'
s
.
capitalize
(
)
'
A, bcd
'
Python Strings