将字符串编码为Unicode格式,并输出:
msg = "我爱北京" print(msg.encode(encoding = "utf-8"))
输出:
再进行解码:
msg = ="我爱北京" print(msg.encode(encoding = "utf-8")) print(msg.encode(encoding = "utf-8").decode(encoding = "utf-8"))