s = ‘匆匆‘print(s)s1 = s.decode("utf-8") # utf-8 转成 Unicode,decode(解码)需要注明当前编码格式print(s1,type(s1)) s2 = s1.encode("gbk") # unicode 转成 gbk,encode(编码)需要注明生成的编码格式print(s2,type(s2)) s3 = s1.encode("utf-8") # unicode 转成 utf-8,encode(编码)注明生成的编码格式print(s3,type(s3))
s = u‘127.0.0.1‘ # unicode编码 s1 = s.encode("utf-8") # 将unicode 编码转换为utf-8 s2 = s.decode("utf-8") # 将unicode 解码转换为utf-8 print s1print s2
原文地址:https://www.cnblogs.com/fanhua999/p/8989808.html
时间: 2024-11-08 09:59:49