Python unicode字符代码?

tkb*_*kbx 5 python unicode

有没有办法在Python中将Unicode字符"插入"字符串?例如,

>>>import unicode
>>>string = u'This is a full block: %s' % (unicode.charcode(U+2588))
>>>print string
This is a full block: ?
Run Code Online (Sandbox Code Playgroud)

Eri*_*ric 11

是的,unicode字符转义:

print u'This is a full block: \u2588'
Run Code Online (Sandbox Code Playgroud)

  • ...或者使用`unichr()`,如果你想从动态代码点创建一个字符(这里似乎不是这样;我为了完整性而添加了它). (3认同)
  • 如果您喜欢更具可读性的内容,可以使用 `u'This is a full block: \N{FULL BLOCK}'`。 (2认同)
  • 我在哪里可以找到像'FULL BLOCK`这样的名字列表? (2认同)