Use title() function to capitalize each word in Python. Python’s Str class provides a function title(), it converts the first character of every word of a given string to upper case
Example how to capitalize each word in Python
Simple example code capitalizes the first character of each word in a string.
txt = 'the brOwn Fox' res = txt.title() print(res)
txt = 'the brOwn Fox' res = " ".join(w.capitalize() for w in txt.split()) # OR use #res = ' '.join(w.upper() + w[1:] for w in s.split()) print(res)
Output: The Brown Fox
Do comment if you have any doubts or suggestions on this Python capitalize topic.
Note: IDE: PyCharm 2021.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.