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()
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.
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())
Output
Welcome To Python Programming, Itsmycode
5 Times 4 Is = To 20
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())
Output
20Dollars Is The Cost Of Python Programming Book
It'S Python'S Interpreter
Top comments (0)