>> "\u2660" '♠' 现在,假设我有一个我不知道名称或编号的角色。是否有一个 Python 函数可以提-6ren">
gpt4 book ai didi

python - 如何在 Python 中找出 unicode 字符的编号/名称?

转载 作者:IT老高 更新时间:2023-10-28 21:51:36 25 4
gpt4 key购买 nike

在 Python 中:

>>> "\N{BLACK SPADE SUIT}"
'♠'
>>> "\u2660"
'♠'

现在,假设我有一个我不知道名称或编号的角色。是否有一个 Python 函数可以提供这样的信息?

>>> wanted_function('♠')
["BLACK SPADE SUIT", "u2660"]

最佳答案

您可以找到 unicodedata模块方便:

>>> s = "\N{BLACK SPADE SUIT}"
>>> s
'♠'
>>> import unicodedata
>>> unicodedata.name(s)
'BLACK SPADE SUIT'
>>> ord(s)
9824
>>> hex(ord(s))
'0x2660'

关于python - 如何在 Python 中找出 unicode 字符的编号/名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13106175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com