Python String capitalize() Method

Capitalizes first character of the string


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.



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.


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