How to find out number/name of unicode character in Python?

前端 未结 1 346
无人共我
无人共我 2020-12-08 06:32

In Python:

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

Now, let\'s say I have a chara

相关标签:
1条回答
  • 2020-12-08 07:11

    You may find the unicodedata module handy:

    >>> s = "\N{BLACK SPADE SUIT}"
    >>> s
    '♠'
    >>> import unicodedata
    >>> unicodedata.name(s)
    'BLACK SPADE SUIT'
    >>> ord(s)
    9824
    >>> hex(ord(s))
    '0x2660'
    
    0 讨论(0)
提交回复
热议问题