Get unicode code point of a character using Python

后端 未结 5 1237
余生分开走
余生分开走 2020-12-04 20:54

In Python API, is there a way to extract the unicode code point of a single character?

Edit: In case it matters, I\'m using Python 2.7.

5条回答
  •  没有蜡笔的小新
    2020-12-04 21:27

    >>> 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
    

提交回复
热议问题