Home » Python String | capitalize() method with Examples

Python String | capitalize() method with Examples

by Online Tutorials Library

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: TutorAspire New value: TutorAspire 

Python String Capitalize() Method Example 2

What if first character already exist in uppercase.

Output:

Old value: TutorAspire New value: TutorAspire 

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: #tutoraspire  New value: #tutoraspire  --------digit---------  Old value: 1-tutoraspire  New value: 1-tutoraspire  

Next TopicPython Strings

You may also like