Cheap Jerseys Cheap NFL Jerseys Cheap NFL Jerseys Cheap Football jerseys Cheap NFL Jerseys Wholesale Jerseys Cheap NHL Jerseys Cheap Jerseys From China Cheap MLB Jerseys Cheap Jerseys Cheap Jerseys Cheap Jerseys Wholesale Jerseys Python String istitle() Method - WTMatter

Python String istitle() Method

Python String Istitle() Method

This is a tutorial of the Python String istitle() method. Learn to check if a given string is in Title Case or not with the help of illustrative examples.

Python String istitle()

The str.istitle() method returns True either if the given string is in Title Case and if not it returns False.

Note. A String in which the first character of all the words is in Uppercase is known as a Title Cased String.

Similarly, you can also use the Python String methods islower() and isupper() to check if a given string in either in the Lower Case or Upper Case respectively.

Syntax

Given below is the syntax of the str.istitle() method.

istitle() Parameters

This method does not take any arguments as it only checks the given string on which it is applied, so no additional data is required in the form of arguments.

istitle() Return Value

It returns the boolean value True or False according to the following logic.

  • Returns True if the given string is in Title Case.
  • Returns False if not the given string is not in Title Case.

Examples

Given below are the two examples demonstrating the usage of the Python String istitle() method.

Example 1. Checking if a given String is in Title Case or not using str.istitle() method

In this example, we’re applying the method istitle() on several different strings to check the result, for what strings it returns True and for what it returns False.

#lowercase string
line = "this string is in lowercase"
print(line.istitle())

#uppercase string
line = "THIS STRING IS IN UPPERCASE"
print(line.istitle())

#alternate case
line = "ThIs sTrInG Is iN AlTeRnAtE CaSe"
print(line.istitle())

#Title Case
line ="This String Is In Title Case"
print(line.istitle())

Output.

False
False
False
True

Example 2. Using the Python String istitle() method with if-else statement

In the following example, we’ve directly used the str.istitle() method as the condition for the if-else statement to print a string accordingly after checking if the given string is in Title Case or not.

#Using str.istitle() with if-else statement

#Given String
name = "Gurmeet Singh"

if name.istitle():
    print("name is in Title Case.")
else:
    print("name is not in Title Case.")

Output.

name is in Title Case.

I hope you found this guide useful. If so, do share it with others who are willing to learn Python and other programming languages. If you have any questions related to this article, feel free to ask us in the comments section.

And do not forget to subscribe to WTMatter!

Subscribe To WTMatter!

Receive updates of our latest articles via email. Enter your email address below to get started.

Leave a Reply

Your email address will not be published. Required fields are marked *