a、将字符串转换成utf-8编码的字节,并输出,然后将该字节在转换成utf-8编码字符串,在输出
b、将字符串转换后才能gbk编码的字节,并输出,然后将该字节在转换成gbk编码字符串,在输出
def main(): n = "老男孩" nBytes_utf = n.encode('utf-8') nStr_utf = nBytes_utf.decode('utf-8') print(nBytes_utf) print(nStr_utf) nBytes_gbk = n.encode('gbk') nStr_gbk = nBytes_gbk.decode('gbk') print(nBytes_gbk) print(nStr_gbk) if __name__ == '__main__': main()
原文地址:http://blog.51cto.com/laobaiv1/2066970
时间: 2024-10-11 19:00:51