使用 Python 获取字符的 unicode 代码点 [英] Get unicode code point of a character using Python
本文介绍了使用 Python 获取字符的 unicode 代码点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Python API 中,有没有办法提取单个字符的 unicode 代码点?
In Python API, is there a way to extract the unicode code point of a single character?
以防万一,我使用的是 Python 2.7.
In case it matters, I'm using Python 2.7.
推荐答案
>>> ord(u"ć")
263
>>> u"café"[2]
u'f'
>>> u"café"[3]
u'xe9'
>>> for c in u"café":
... print repr(c), ord(c)
...
u'c' 99
u'a' 97
u'f' 102
u'xe9' 233
这篇关于使用 Python 获取字符的 unicode 代码点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文