Python String title()

The syntax of title() is:

str.title()

title() Parameters

title() method doesn't take any parameters.


Return Value from title()

title() method returns a title cased version of the string. Meaning, the first character of each word is capitalized (if the first character is a letter).


Example 1: How Python title() works?

Output

My Favorite Number Is 25.
234 K3L2 *43 Fun

Example 2: title() with apostrophes

Output

He'S An Engineer, Isn'T He?

title() capitalizes the first letter after apostrophes as well.

To solve this issue, you can use regex as follows:


Example 3: Using Regex to Title Case String

Output

He's An Engineer, Isn't He?