Python Jupyter Notebook:如何从Wikipedia十六进制值(如U + 1F0A1)打印Unicode字符?

576*_*76i 2 python unicode

我想在jupyter笔记本中使用unicode中的纸牌字符。

Unicode代码在这里。https://zh.wikipedia.org/wiki/Playing_cards_in_Unicode

印刷西服作品

print('\u2660')
Run Code Online (Sandbox Code Playgroud)

退货

例如,黑桃A的Unicode A为U + 1F0A1。

我可以粘贴该字符并将其打印出来。

print('') 
Run Code Online (Sandbox Code Playgroud)

我可以编码

''.encode('utf-8')
Run Code Online (Sandbox Code Playgroud)

b'\ xf0 \ x9f \ x82 \ xa1'

但是,如何通过维基百科中的代码“ U + 1F0A1”来打印呢?

Mar*_*nen 5

还有另一种转义码(大写的U),需要八位数字:

>>> print('\U0001F0A1')

Run Code Online (Sandbox Code Playgroud)

您也可以通过转换数字进行打印:

>>> chr(0x1f0a1)
''
>>> print(chr(0x1f0a1))

Run Code Online (Sandbox Code Playgroud)

因此,您可以以编程方式生成一张52张卡片的办公桌,如下所示:

>>> suit = 0x1f0a0,0x1f0b0,0x1f0c0,0x1f0d0
>>> rank = 1,2,3,4,5,6,7,8,9,10,11,13,14
>>> for s in suit:
...     for r in rank:
...         print(chr(s+r),end='')
...     print()
... 




Run Code Online (Sandbox Code Playgroud)