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()返回True
,否则返回False。 如果字符串的所有单词均以大写字母开头,而所有其他字符均以小写字母开头,则该字符串以标题区分。 如果字符串不包含任何用大写字母括起来的字符,则此函数还将返回False。
Python字符串istitle() (Python String istitle())
Let’s look at some examples of Python String istitle() function.
我们来看一些Python String istitle()函数的示例。
s = 'A Big Cat'
print(s.istitle())
Output: True
输出: True
s = 'A BIG Cat'
print(s.istitle())
Output: False
because of ‘BIG’.
输出:由于“ BIG”而为False
。
s = 'A big Cat'
print(s.istitle())
Output: False
because of ‘big’.
输出:由于“大”而为False
。
s = 'a big cat'
print(s.istitle())
Output: False
because the words are not starting with uppercase letter.
输出: False
因为单词不是以大写字母开头。
s = 'A'
print(s.istitle())
Output: True
输出: True
s = ''
print(s.istitle())
Output: False
because string is empty.
输出: False
因为字符串为空。
s = '2019'
print(s.istitle())
Output: False
because string doesn’t contain any titlecased characters.
输出: False
因为string不包含任何带标题大写的字符。
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.
输出: True
因为Â,Ɓ和Ȼ是标题区分大小写的字母。
打印所有Unicode标题大写的字符 (Print all Unicode title-cased characters)
Here is a simple code snippet to print all the Unicode characters that are title cased.
这是一个简单的代码段,用于打印所有带有标题大小写的Unicode字符。
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
参考: 官方文档