Python Tutorial Python Advanced Python References Python Libraries

Python String - capitalize() Method



The Python capitalize() method returns 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.

Return Value

Returns the string with first character of the specified string in uppercase and rest into lowercase.

Example:

In the example below, 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)

The output of the above code will be:

heLLo woRld!
Hello world!

❮ Python String Methods

5