Unicodedata – Python 中的 Unicode 数据库
pythonserver side programmingprogramming更新于 2025/10/24 12:28:17
在本文中,我们将了解 Python 3.x 或更早版本中的 Unicodedata – Unicode 数据库。
Unicode 字符数据库模块为字符提供 Unicode 的所有功能。该模块使用与模块中提到的相同的名称和符号。
现在让我们看看模块中可用的一些函数。
查找函数
此函数允许我们获取输入中传递的相应名称的符号。
示例
import unicodedata
print (unicodedata.lookup('HYPHEN'))
print (unicodedata.lookup('HIGH VOLTAGE SIGN') )
print (unicodedata.lookup('NO ENTRY') )
输出
- ⚡
名称函数
这允许我们获取输入中传递的相应符号。
示例
import unicodedata print (unicodedata.name(u'&')) print (unicodedata.name(u'@') ) print (unicodedata.name(u'`') )
输出
AMPERSAND COMMERCIAL AT GRAVE ACCENT
Category 函数
这使我们能够检测作为输入传递的符号/字母/整数的类别。
示例
import unicodedata print (unicodedata.category(u'&')) print (unicodedata.category(u'1') ) print (unicodedata.category(u'a') )
输出
Po Nd Ll
结论
在本文中,我们将了解 Unicode 字符数据库和一些相关函数。
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

