Python capitalize() Method
Description
Python capitalize() converts the first letter of the string to uppercase and the other letters to lowercase. For 8-bit byte encoding, it depends on the local environment.
Syntax
capitalize() method syntax:
str.capitalize()
Parameters
- None.
Return Value
This method returns a string with the first character capitalized.
Example
The following example demonstrates the capitalize() method:
>>>s = 'a, B'
>>> s.capitalize()
'A, b'
>>> s = ' a, B' # a has a space before it
>>> s.capitalize()
' a, b'
>>> s = 'a, BCD'
>>> s.capitalize()
'A, bcd'
Other Extensions
Python Strings