isupper_Python字符串isupper()

isupper

Python string isupper()

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
GitHub Repository. GitHub存储库中签出更多Python示例。

Reference: Official Documentation

参考: 官方文档

翻译自: https://www.journaldev.com/24273/python-string-isupper

isupper

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值