字符串互转utf-8、gbk

有如下字符串:n = "路飞学城"(编程题)  

    - 将字符串转换成utf-8的字符编码,再将转换的字节重新转换为utf-8的字符编码

n = "路飞学城"

n_e_u = n.encode("utf-8")     #    b'\xe8\xb7\xaf\xe9\xa3\x9e\xe5\xad\xa6\xe5\x9f\x8e'
n_d_u = n_e_u.decode("utf-8")    #    路飞学城


    - 将字符串转换成gbk的字符编码,再将转换的字节重新转换为utf-8的字符编码

n = "路飞学城"

n_e_g = n.encode("gbk")     #    b'\xc2\xb7\xb7\xc9\xd1\xa7\xb3\xc7'
n_d_g = n_e_g.decode("gbk")    #    路飞学城

 

你可能感兴趣的:(字符串互转utf-8、gbk)