博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python字符串isalpha()
阅读量:2532 次
发布时间:2019-05-11

本文共 1999 字,大约阅读时间需要 6 分钟。

Python String isalpha() function returns True if all the characters in the string are alphabets, otherwise False. If the string is empty then this function returns False.

如果字符串中的所有字符都是字母,则Python String isalpha()函数将返回True ,否则返回False。 如果字符串为空,则此函数返回False。

Python字符串isalpha() (Python String isalpha())

Alphabetic characters are those characters defined in the Unicode character database as “Letter”, i.e., those with general category property being one of “Lm”, “Lt”, “Lu”, “Ll”, or “Lo”.

字母字符是在Unicode字符数据库中定义为“字母”的那些字符,即,具有一般类别属性为“ Lm”,“ Lt”,“ Lu”,“ Ll”或“ Lo”之一的那些字符。

Let’s look at some of the examples of isalpha() function.

让我们看一下isalpha()函数的一些示例。

s = 'Hello'print(s.isalpha())

Output: True because all the characters in the string are alphabets.

输出: True因为字符串中的所有字符都是字母。

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

Output: False because the string contains numbers.

输出: False因为字符串包含数字。

s = ''print(s.isalpha())

Output: False because it’s an empty string.

输出: False因为它是一个空字符串。

s = 'çå'print(s.isalpha())

Output: True because ç and å are defined as letters in the Unicode character database.

输出: True因为ç和å在Unicode字符数据库中定义为字母。

在Python中打印所有Alpha字符 (Printing all Alpha characters in Python)

We can use unicode module to check if a character is alpha or not. Here is the program to print all the alpha Unicode characters.

我们可以使用unicode模块来检查字符是否为字母。 这是打印所有字母Unicode字符的程序。

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

Output:

输出:

...ffd7: ᅲ (HALFWIDTH HANGUL LETTER YU)ffda: ᅳ (HALFWIDTH HANGUL LETTER EU)ffdb: ᅴ (HALFWIDTH HANGUL LETTER YI)ffdc: ᅵ (HALFWIDTH HANGUL LETTER I)Total Number of Alpha Unicode Characters = 48832

I have provided only partial output because the number of alpha Unicode characters is huge.

我只提供了部分输出,因为alpha Unicode字符的数量很大。

. 签出更多Python示例。

Reference: ,

参考: ,

翻译自:

转载地址:http://xlmzd.baihongyu.com/

你可能感兴趣的文章
算法导论笔记(四)算法分析常用符号
查看>>
ultraedit激活
查看>>
总结(6)--- python基础知识点小结(细全)
查看>>
亿级曝光品牌视频的幕后设定
查看>>
ARPA
查看>>
JSP开发模式
查看>>
我的Android进阶之旅------>Android嵌入图像InsetDrawable的使用方法
查看>>
Detours信息泄漏漏洞
查看>>
win32使用拖放文件
查看>>
Android 动态显示和隐藏软键盘
查看>>
raid5什么意思?怎样做raid5?raid5 几块硬盘?
查看>>
【转】how can i build fast
查看>>
null?对象?异常?到底应该如何返回错误信息
查看>>
django登录验证码操作
查看>>
(简单)华为Nova青春 WAS-AL00的USB调试模式在哪里开启的流程
查看>>
图论知识,博客
查看>>
[原创]一篇无关技术的小日记(仅作暂存)
查看>>
20145303刘俊谦 Exp7 网络欺诈技术防范
查看>>
原生和jQuery的ajax用法
查看>>
iOS开发播放文本
查看>>