Python String istitle() returns True
if the string is title cased and not empty, otherwise it returns False. A string is title cased when all its words start with Uppercase characters and all other characters are in lowercase. If the string doesn’t contain any titlecased character, then also this function returns False.
Python String istitle()
Let’s look at some examples of Python String istitle() function.
s = 'A Big Cat'
print(s.istitle())
Output: True
s = 'A BIG Cat'
print(s.istitle())
Output: False
because of ‘BIG’.
s = 'A big Cat'
print(s.istitle())
Output: False
because of ‘big’.
s = 'a big cat'
print(s.istitle())
Output: False
because the words are not starting with uppercase letter.
s = 'A'
print(s.istitle())
Output: True
s = ''
print(s.istitle())
Output: False
because string is empty.
s = '2019'
print(s.istitle())
Output: False
because string doesn’t contain any titlecased characters.
Let’s look at an example where the string contains special characters.
s = 'Â Ɓig Ȼat'
print(s.istitle())
Output: True
because Â, Ɓ and Ȼ are title cased letters.
Print all Unicode title-cased characters
Here is a simple code snippet to print all the Unicode characters that are title cased.
import unicodedata
count = 0
for codepoint in range(2 ** 16):
ch = chr(codepoint)
if ch.istitle():
print(u'{:04x}: {} ({})'.format(codepoint, ch, unicodedata.name(ch, 'UNNAMED')))
count = count + 1
print(f'Total Number of Title Unicode Characters = {count}')
Output:
0041: A (LATIN CAPITAL LETTER A)
0042: B (LATIN CAPITAL LETTER B)
0043: C (LATIN CAPITAL LETTER C)
...
ff38: X (FULLWIDTH LATIN CAPITAL LETTER X)
ff39: Y (FULLWIDTH LATIN CAPITAL LETTER Y)
ff3a: Z (FULLWIDTH LATIN CAPITAL LETTER Z)
Total Number of Title Unicode Characters = 1185
Reference: Official Documentation