![]() |
VOOZH | about |
In this article, we will see how to convert the string to a title case in Python. The str.title() method capitalizes the first letter of every word.
Geeks For Geeks
Explanation:
"python is fun" to title case."Geeks For Geeks".Table of Content
string.capwords()Thestring.capwords() function splits the text into words capitalizes the first letter of each word, and joins them back together with spaces.
Geeks For Geeks
Explanation:
string.capwords() function splits the input string "geeks for geeks" into words based on spaces, capitalizes the first letter of each word, and converts the rest to lowercase."Geeks For Geeks"Manually capitalize each word in a string using a list comprehension and the str.capitalize() method.
Geeks For Geeks
Explanation
s.split() method splits the string "geeks for geeks" into a list of words: ["geeks", "for", "geeks"]. Each word is then capitalized using word.capitalize() inside a generator expression." ".join() method combines the capitalized words back into a single string with spaces, resulting in "Geeks For Geeks".