Python String capitalize() Method

Python capitalize() method converts first character of the string into uppercase without altering the whole string. It changes the first character only and skips rest of the string unchanged.

Signature

Parameters

No parameter is required.

Return Type

It returns a modified string.

Python String Capitalize() Method Example 1

Output:

Old value: javatpoint
New value: Javatpoint

Python String Capitalize() Method Example 2

What if first character already exist in uppercase.

Output:

Old value: Javatpoint	
New value: Javatpoint

It returns the same string without any alteration.

Python String Capitalize() Method Example 3

What if first character is a digit or non-alphabet character? This method does not alter character if it is other than a string character.

Output:

Old value: #javatpoint
New value: #javatpoint
--------digit---------
Old value: 1-javatpoint
New value: 1-javatpoint

Next TopicPython Strings




Latest Courses