请看这个python代码
print "input your chinese name"
s = raw_input("please enter to be continued")
print 'your name is ' +s
l = len(s)
print 'length of your chinese name is '+str(l)
a = unicode(s,"GBK") //将前面的s转换为unicode编码
l = len(a)
print 'I am sorry we should use unicode char!'+str(l)
输出结果为:
我们可以明显的看到,我爱老王四个字对应的ascii码长度为 8 而对应的unicode码长度为4
说明unicode码是一个中文字一个字节的