In the previous article, we have discussed Python String isspace() Method Examples
istitle() Method in Python:
If the string is titlecased, the istitle() function returns True. If it does not, it returns False.
Syntax:
string.istitle()
Parameters: This function has no parameters.
Return Value:
The istitle() method gives:
- True if the string is titlecased.
- If the string is not titlecased or is empty, it returns False.
Examples:
Example1:
Input:
Given string = 'Welcome To Python-Programs' Given string = 'good morning btechgeeks' Given string = 'Hello All @ This Is Btechgeeks'
Output:
The given string = Welcome To Python-Programs Checking if the given string is titlecased or not = True The given string = good morning btechgeeks Checking if the given string is titlecased or not = False The given string = Hello All @ This Is Btechgeeks Checking if the given string is titlecased or not = True
Example2:
Input:
Given string = 'Welcome To Python-programs' Given string = '12345 Hello All' Given string = 'GOOD MORNING BTECHGEEKS'
Output:
The given string = Welcome To Python-programs Checking if the given string is titlecased or not = False The given string = 12345 Hello All Checking if the given string is titlecased or not = True The given string = GOOD MORNING BTECHGEEKS Checking if the given string is titlecased or not = False
String istitle() Method Examples in Python
Method #1: Using Built-in Functions (Static Input)
Approach:
- Give the string as static input and store it in a variable.
- Apply istitle() function to the given string in which if the string is titlecased, the istitle() function returns True. If it does not, it returns False.
- Store it in another variable.
- Print the above-given String.
- Print the result after checking if the given string is titlecased or not.
- Similarly, do the same for other strings and print the result.
- The Exit of Program.
Below is the implementation:
# Give the string as static input and store it in a variable. gvn_strng1 = 'Welcome To Python-Programs' # Apply istitle() function to the given string in which if the string # is titlecased, the istitle() function returns True. If it does not, # it returns False. # Store it in another variable. rslt_1 = gvn_strng1.istitle() # Print the above-given String. print("The given string = ", gvn_strng1) # Print the result after checking if the given string is titlecased or not print("Checking if the given string is titlecased or not = ", rslt_1) # Similarly, do the same for other strings and print the result. gvn_strng2 = 'good morning btechgeeks' rslt_2 = gvn_strng2.istitle() print("The given string = ", gvn_strng2) print("Checking if the given string is titlecased or not = ", rslt_2) gvn_strng3 = 'Hello All @ This Is Btechgeeks' rslt_3 = gvn_strng3.istitle() print("The given string = ", gvn_strng3) print("Checking if the given string is titlecased or not = ", rslt_3)
Output:
The given string = Welcome To Python-Programs Checking if the given string is titlecased or not = True The given string = good morning btechgeeks Checking if the given string is titlecased or not = False The given string = Hello All @ This Is Btechgeeks Checking if the given string is titlecased or not = True
Method #2: Using Built-in Functions (User Input)
Approach:
- Give the string as user input using the input() function and store it in a variable.
- Apply istitle() function to the given string in which if the string is titlecased, the istitle() function returns True. If it does not, it returns False.
- Store it in another variable.
- Print the above-given String.
- Print the result after checking if the given string is titlecased or not.
- Similarly, do the same for other strings and print the result.
- The Exit of Program.
Below is the implementation:
# Give the string as user input using the input() function and store it in a variable. gvn_strng1 = input("Enter some Random String = ") # Apply istitle() function to the given string in which if the string # is titlecased, the istitle() function returns True. If it does not, # it returns False. # Store it in another variable. rslt_1 = gvn_strng1.istitle() # Print the above-given String. print("The given string = ", gvn_strng1) # Print the result after checking if the given string is titlecased or not print("Checking if the given string is titlecased or not = ", rslt_1) # Similarly, do the same for other strings and print the result. gvn_strng2 = input("Enter some Random String = ") rslt_2 = gvn_strng2.istitle() print("The given string = ", gvn_strng2) print("Checking if the given string is titlecased or not = ", rslt_2) gvn_strng3 = input("Enter some Random String = ") rslt_3 = gvn_strng3.istitle() print("The given string = ", gvn_strng3) print("Checking if the given string is titlecased or not = ", rslt_3)
Output:
Enter some Random String = Welcome To Python-programs The given string = Welcome To Python-programs Checking if the given string is titlecased or not = False Enter some Random String = 12345 Hello All The given string = 12345 Hello All Checking if the given string is titlecased or not = True Enter some Random String = GOOD MORNING BTECHGEEKS The given string = GOOD MORNING BTECHGEEKS Checking if the given string is titlecased or not = False
Are you facing difficulties in finding all the methods that a string object can call in python? Have a glance at this Python String Method Examples Tutorial & meet such challenges with ease.