Skip to content

Python title vs capitalize functions | Difference

  • by

The difference between Python title vs capitalize functions is how they convert (return) a string.

Where title() function changes the first character in each word to Uppercase and the remaining characters to Lowercase in the string and returns a new string.

str.title()

And the capitalize() method converts the first character of a string to a capital (uppercase) letter.

str.capitalize()

Example difference title vs capitalize in Python

Simple example code title() changes every word, but capitalize() only the first word in a sentence:

a = 'silly question'
print(a.title())

a = 'silly question'
print(a.capitalize())

Output:

Python title vs capitalize functions

Do comment if you have any doubts and suggestions on this Python comparison 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.