Python String istitle() Method



The python string istitle() method is used to check whether the string is a titlecased string. This method returns true if the c string is a titlecased string and there is atleast one character. The uppercase characters may only follow uncased characters and lowercase characters only cased ones. If this rule is followed, then this method returns true. Otherwise, it returns false.

Let us look into more details of this method in the following section.

Syntax

Following is the syntax for the python string istitle() method −

str.istitle()

Parameters

The python string istitle() method doesnot contain any parameters.

Return Value

The python string istitle() method returns true if all the words in the string are titlecased and there is at least one character and false otherwise.

Example

The following is an example of the python string istitle() method. In this program, a string "Tutorialspoint!" is created and the istitle() function is invoked to check whether the input string is titlecased or not.

str = "Tutorialspoint!"
result=str.istitle()
print("Is the input string titlecased?", result)

On executing the above program, the following output is generated -

Is the input string titlecased? True

Example

The titlecase indicates that the lower case letters are always followed by the cased characters and the uppercase letters must always be followed by the uncased characters.

str = "TutorialsPoint!"
result=str.istitle()
print("Is the input string titlecased?", result)

The following is the output obtained by executing the above program -

Is the input string titlecased? False

Example

Every word of the input string must be titlecased for the istitle() method to return true.

str = "Hello world"
result=str.istitle()
print("Is the input string titlecased?", result)

The following output is obtained by executing the above program -

Is the input string titlecased? False

Example

The python string istitle() method returns false even if one word of the created string is not titleccased.

str = "Hello!Welcome To TUTORIALSPOINT."
result=str.istitle()
print("Is the input string titlecased?", result)

The above program, on executing, displays the following output -

Is the input string titlecased? False

Example

The created string can contain numbers also. But, following the numbers, only uppercased character must be there for it to be titlecased.

str = "123Hello World."
result=str.istitle()
print("Is the input string titlecased?", result)

The output of the above program is displayed as follows -

Is the input string titlecased? True
python_strings.htm
Advertisements