DEV Community

Srinivas Ramakrishna for ItsMyCode

Posted on • Originally published at itsmycode.com on

3 2

Python String title()

The Python String title() method is a built-in function that returns a string where the first character of each word is uppercase. It is also called a title case string.

Also read How to Fix AttributeError: ‘numpy.ndarray’ object has no attribute ‘index’

In this article, we will learn about the Python String title() method with the help of examples.

title() Syntax

The Syntax of title() method is:

str.title()
Enter fullscreen mode Exit fullscreen mode

title() Parameters

The title() method does not take any parameters.

title() Return Value

The title() method returns the title cased version of a string. The first character of each word in a string is capitalized.

**Note:**  The first letter is capitalized if it's a valid letter. In the case of digits or numbers, the conversion to uppercase will not happen.
Enter fullscreen mode Exit fullscreen mode

Example 1: How Python title() works?

text = "Welcome to python programming, itsmycode"
print(text.title())

text = "5 times 4 is = to 20 "
print(text.title())
Enter fullscreen mode Exit fullscreen mode

Output

Welcome To Python Programming, Itsmycode
5 Times 4 Is = To 20 
Enter fullscreen mode Exit fullscreen mode

Example 2: title() method in case of number and apostrophes

The presence of digits or number before the word will not affect the working of the function. The character after the digit is considered as the first character.

In case of apostrophes the title() capitalizes the first letter and the letter after apostrophes as well.

# incase the of numbers or digits at the beginning
text = "20dollars is the cost of Python programming book"
print(text.title())

# in case of apostrophes
text = "it's python's interpreter"
print(text.title())
Enter fullscreen mode Exit fullscreen mode

Output

20Dollars Is The Cost Of Python Programming Book
It'S Python'S Interpreter
Enter fullscreen mode Exit fullscreen mode

Image of Stellar post

🚀 Stellar Dev Diaries Series: Episode 1 is LIVE!

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

Top comments (0)

Neon image

Set up a Neon project in seconds and connect from a Python application

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started →

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay