Python String istitle() Method

The Python istitle() method is a string method that returns True if all words in a string start with an uppercase letter and the rest of the word are lowercase letters, otherwise False. Symbols and numbers are ignored.

Here are some examples of using the istitle() method:

# Example 1: A simple example of title testing using istitle() method[^2^][6]
s = 'Python Is Good.'
print(s.istitle())

# Prints True

s = 'Python is good'
print(s.istitle())

# Prints False

s = 'This Is @ Symbol.'
print(s.istitle())

# Prints True

s = '99 Is A Number'
print(s.istitle())

# Prints True

s = 'PYTHON'
print(s.istitle())

# Prints False

# Example 2: The istitle() method can be used with the title() method to check a string before converting it to a titlecased string[^3^][3]
ustr=input("Enter a string: ")
if not ustr.istitle():
    ustr = ustr.title()
    print('Converted to TitleCase:', ustr)
else:
    print('You entered a TitleCase string')

If you have any questions about this code, you can drop a line in comment.

Comments

Popular posts from this blog

Python chr() Built in Function

Stock Market Predictions with LSTM in Python

Collections In Python

Python Count Occurrence Of Elements

Python One Liner Functions