【问题标题】:How to print a variable that contains a unicode character?如何打印包含 unicode 字符的变量?
【发布时间】:2013-05-09 16:06:33
【问题描述】:
print u'\u0D05'
a = '\u0D05'
print a

print a 给出\u0D05 作为输出,但我想打印它所代表的unicode 字符,即。我怎样才能做到这一点?

【问题讨论】:

    标签: python python-2.7 unicode


    【解决方案1】:

    \u 转义在非 Unicode 字符串中没有意义。你需要做a = u'\u0D05'

    如果您说您是从其他地方获取字符串并且需要解释其中的 unicode 转义,那么请执行 print a.decode('unicode-escape')

    【讨论】:

      猜你喜欢
      • 2020-08-01
      • 1970-01-01
      • 2014-09-16
      • 2021-04-03
      • 1970-01-01
      • 1970-01-01
      • 2021-06-08
      • 2015-02-01
      • 2018-06-22
      相关资源
      最近更新 更多