Skip to content

Python title function | Uppercase first character of the word

  • by

The title() method is used to convert the first character in every word of a given sentence in Python. Actually, this method returns a string with first letter of each word capitalized.


Python title function example

Simple example code capitalized the first character of each word of a given sentence (if the first character is a letter).

text = 'My favorite number is 7.'

text = 'Hello robot 700'


Python title function

Another example makes the first letter in each word upper case:

txt = "hello a23b12 and 7d7ea"

res = txt.title()


Output: Hello A23B12 And 7D7Ea

Do comment if you have any doubts or suggestions on this Python function topic.

Note: IDE: PyCharm 2021.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.