赞
踩
reference: https://blog.csdn.net/qq_34802511/article/details/87705201
unicodestring = u"Hello world"
utf8string = unicodestring.encode(“utf-8”)
asciistring = unicodestring.encode(“ascii”)
isostring = unicodestring.encode(“ISO-8859-1”)
utf16string = unicodestring.encode(“utf-16”)
print utf8string,type(utf8string) # 结果:Hello world <type ‘str’>
print asciistring,type(asciistring) # 结果:Hello world <type ‘str’>
print isostring,type(isostring) # 结果:Hello world <type ‘str’>
print utf16string,type(utf16string) # 结果:Hello world <type ‘str’>
plainstring1 = unicode(utf8string, “utf-8”)
plainstring2 = unicode(asciistring, “ascii”)
plainstring3 = unicode(isostring, “ISO-8859-1”)
plainstring4 = unicode(utf16string, “utf-16”)
print plainstring1,type(plainstring1) # 结果:Hello world <type ‘unicode’>
print plainstring2,type(plainstring2) # 结果:Hello world <type ‘unicode’>
print plainstring3,type(plainstring3) # 结果:Hello world <type ‘unicode’>
print plainstring4,type(plainstring4) # 结果:Hello world <type ‘unicode’>
str1 = utf8string.decode(“utf-8”)
str2 = asciistring.decode(“ascii”)
str3 = isostring.decode(“ISO-8859-1”)
str4 = utf16string.decode(“utf-16”)
print str1,type(str1) # 结果:Hello world <type ‘unicode’>
print str2,type(str2) # 结果:Hello world <type ‘unicode’>
print str3,type(str3) # 结果:Hello world <type ‘unicode’>
print str4,type(str4) # 结果:Hello world <type ‘unicode’>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。