欧美一区二区三区,国内熟女精品熟女A片视频小说,日本av网,小鲜肉男男GAY做受XXX网站

Python如何將Unicode中文字符串轉(zhuǎn)換成string字符串

Python如何將Unicode中文字符串轉(zhuǎn)換成string字符串?

普通字符串可以用多種方式編碼成Unicode字符串,具體要看你究竟選擇了哪種編碼:unicodestring=u"Helloworld"#將Unicode轉(zhuǎn)化為普通Python字符串:"encode"utf8string=unicodestring.encode("utf-8"

)asciistring=unicodestring.encode("ascii"

)isostring=unicodestring.encode("ISO-8859-1"

)utf16string=unicodestring.encode("utf-16")#將普通Python字符串轉(zhuǎn)化為Unicode:"decode"plainstring1=unicode(utf8string,"utf-8"

)plainstring2=unicode(asciistring,"ascii"

)plainstring3=unicode(isostring,"ISO-8859-1"

)plainstring4=unicode(utf16string,"utf-16"

)assertplainstring1==plainstring2==plainstring3==plainstring4