【发布时间】:2012-11-30 01:03:53
【问题描述】:
我有这样的代码:
a = "\u0432"
b = u"\u0432"
c = b"\u0432"
d = c.decode('utf8')
print(type(a), a)
print(type(b), b)
print(type(c), c)
print(type(d), d)
然后输出:
<class 'str'> в
<class 'str'> в
<class 'bytes'> b'\\u0432'
<class 'str'> \u0432
为什么在后一种情况下我看到的是字符代码,而不是字符? 如何将 Byte 字符串转换为 Unicode 字符串,以便在输出时我看到的是字符而不是其代码?
【问题讨论】:
标签: python string unicode python-3.x type-conversion