Python String Title method
The String title() method in Python is used to convert the first character in each word to uppercase and the remaining characters to lowercase in the string and returns a new string.
Python String title() Method Syntax:
parameters: title() doesn’t accept any parameter.
Return: str, converted to title case
Python String title() Method Example:
Example 1: Basic usages of Python String title() Method
geeKs foR geEks converted to using title(): Geeks For Geeks Geeks For Geeks converted to using title(): Geeks For Geeks We Are 1 converted to using title(): We Are 1
Getting undesired results while using Python String title() Method
Example 1: title() method considers any non-alphabet as a word boundary.
Expected: He's Smarter , Actual: He'S Smarter.
Explanation: The ‘s’ after He’ is converted to Capital letter, because after ‘(apostrophe) string title() method considers the start of a new word, since s is the first letter after ‘(apostrophe), thus it makes ‘s’ as capital letter.
Example 2: Different word boundaries other than space, when using title() Method
geeks-for-geeks converted using title(): Geeks-For-Geeks
Word around to unexpected behavior of String title() Method
Example 1: Using Regex to fix the unexpected behavior of Python String title() Method.
I Won't Be Working Tomorrow.