Python字符串islower()

时间:2020-02-23 14:43:27  来源:igfitidea点击:

如果字符串中所有大小写的字符均为小写并且至少有一个大小写的字符,则Python String islower()返回True,否则返回False。

Python字符串islower()

大小写字符是指具有通用Unicode类别属性的字符,它们是" Lu"(字母大写)," Ll"(字母小写)或者" Lt"(字母大写)之一。

我们来看一些Python字符串islower()函数的示例。

s = 'abc'
print(s.islower())

输出:True,因为所有的字符串大小写字符都是小写。

s = 'Abc'
print(s.islower())

输出:False,因为其中一个大小写字符为大写。

s = '123'
print(s.islower())

输出:False,因为字符串中没有大小写字符。

s = 'a123'
print(s.islower())

输出:True,因为所有的字符串大小写字符都是小写。

s = 'åçĕń'
print(s.islower())

输出:True,因为所有的字符串大小写字符都是小写。

打印所有小写Unicode字符

我们可以使用unicodedata模块来检查字符是否为小写。
这是打印所有小写Unicode字符的代码段。

import unicodedata

count = 0
for codepoint in range(2 ** 16):
  ch = chr(codepoint)
  if ch.islower():
      print(u'{:04x}: {} ({})'.format(codepoint, ch, unicodedata.name(ch, 'UNNAMED')))
      count = count + 1
print(f'Total Number of Lowercase Unicode Characters = {count}')

输出:

0061: a (LATIN SMALL LETTER A)
0062: b (LATIN SMALL LETTER B)
...
ff58: x (FULLWIDTH LATIN SMALL LETTER X)
ff59: y (FULLWIDTH LATIN SMALL LETTER Y)
ff5a: z (FULLWIDTH LATIN SMALL LETTER Z)
Total Number of Lowercase Unicode Characters = 1617