py2 中文碰到的一个问题
資深大佬 : oldbird 16
因为宿主软件的原因,必须使用 py2 。 WIN10 中文系统,在 PY2.7 的 IDLE 里做了个试验,输入:
a=”汽车”
print a,len(a),type(a)
b=a.decode(‘gbk’)
print b,len(b),type(b)
c=unicode(a)
print c,len(c),type(c)
d=u’汽车’
print d,len(d),type(d)
输出:
汽车 4 <type ‘str’>
汽车 2 <type ‘unicode’>
汽车 2 <type ‘unicode’>
Æû³µ 4 <type ‘unicode’> 不理解 d 为什么输出乱码,请教。
大佬有話說 (7)