isupper
![Python string isupper()](https://cdn.journaldev.com/wp-content/uploads/2018/12/python-string-isupper.png)
Python String isupper() function returns
True
if all the cased characters are in Uppercase. If the string is empty or there are no cased characters then it returns
False
.
如果所有大小写的字符均为大写,则Python String isupper()函数将返回True
。 如果字符串为空或没有大小写字符,则返回False
。
Python字符串isupper() (Python String isupper())
Cased characters are those with general category property being one of “Lu” (Letter, uppercase), “Ll” (Letter, lowercase), or “Lt” (Letter, titlecase).
大小写字符是那些具有常规类别属性的字符,它们是“ Lu”(字母大写),“ Ll”(字母小写)或“ Lt”(字母大写)之一。
Let’s look at some examples of isupper() function.
让我们看一下isupper()函数的一些示例。
s = 'HELLO WORLD'
print(s.isupper())
Output: True
because all the cased characters are in Uppercase.
输出: True
因为所有大小写的字符均为大写。
s = 'Hello World'
print(s.isupper())
Output: False
because there are some cased characters in lowercase.
输出: False
因为有一些小写的大小写字符。
s = 'HELLO WORLD 2019'
print(s.isupper())
Output: True
because all the cased characters are in Uppercase. The numbers in the string are not cased characters.
输出: True
因为所有大小写的字符均为大写。 字符串中的数字不是大小写字符。
s = ''
print(s.isupper())
Output: False
because string is empty.
输出: False
因为字符串为空。
s = '2019'
print(s.isupper())
Output: False
because string doesn’t have any cased character.
输出: False
因为string没有任何大小写的字符。
Let’s look at an example with special characters string.
让我们看一个带有特殊字符串的示例。
s = 'ÂƁȻ2019'
print(s.isupper())
Output: True
because all the cased characters in the string are in Uppercase.
输出: True
因为字符串中所有大小写的字符均为大写。
打印所有大写字母 (Print All Uppercase Cased Characters)
Here is a simple program to print information about all the Uppercase cased characters.
这是一个用于打印有关所有大写字母大写字符的信息的简单程序。
import unicodedata
count = 0
for codepoint in range(2 ** 16):
ch = chr(codepoint)
if ch.isupper():
print(u'{:04x}: {} ({})'.format(codepoint, ch, unicodedata.name(ch, 'UNNAMED')))
count = count + 1
print(f'Total Number of Uppercase 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 Uppercase Unicode Characters = 1154
Reference: Official Documentation
参考: 官方文档
isupper