Python String capitalize() Method

Capitalizes first character of the string

Usage

The capitalize() method returns a copy of the string with its first character capitalized and the rest lowercased.

The method does not change the original string.

Syntax

string.capitalize()

Basic Example

Example: Capitalize the string

S = 'bob is a CEO at ABC.'
x = S.capitalize()
print(x)    # Bob is a ceo at abc.

Non-alphabetic First Character

For the string with non-alphabetic first character, the first character is kept unchanged while the rest is changed to lowercase.

Example:

S = '42 is my FAVOURITE number.'
x = S.capitalize()
print(x)    # 42 is my favourite number.