Limitations of String title() Method
There are some limitations of string title() function. We have mentioned some of the limitations that you might notice:
Example 1: title() method considers any non-alphabet as a word boundary.
Python3
string = "He's smarter." expected_string = "He's Smarter" print ( "Expected:" , expected_string, ", Actual:" , string.title()) |
Output:
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
Here, even though there are no spaces separated words, still Python String title() method converts the String title case considering ‘-‘(hyphen) as word boundaries.
Python3
string = "geeks-for-geeks" print (string, "converted using title():" , string.title()) |
Output:
geeks-for-geeks converted using title(): Geeks-For-Geeks
Python String Title method
Python String title() method returns a new string after converting the first letter of every word to uppercase(capital) and keeping the rest of the letters lowercase.
Example: Make string title case
Python3
print ( "usE stRing title Method" .title()) |
Output
Use String Title Method