Python - String capitalize() Method


Advertisements

The string capitalize() method is used to return the string with first character of the specified string into uppercase and rest into lowercase. Any symbol, space, special character or number in the string is ignored while applying this function. Only Alphabets are converted. Please note that it does not change the original string and only returns the converted version of the given string.

Syntax


string.capitalize()

Parameters

No parameter is required.

Example:

In the below example, capitalize() method is used to convert first character of the string called MyString into uppercase and rest into lowercase. This method does not change the MyString and only returns the converted version of it.

MyString = "heLLo woRld!"
NewString = MyString.capitalize()

print(MyString)
print(NewString)

Output

heLLo woRld!

Hello world!

String Methods
Advertisements