Python字符串istitle()

Python string istitle()

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

Reference: Official Documentation

参考: 官方文档

翻译自: https://www.journaldev.com/24263/python-string-istitle

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值