#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = '人生入戏' #python3在编码时会把str编码成utf-8的bytes类型(gbk的bytes类型),再解码为utf-8、gbk等等 msg = "你好" # unicode
print(msg.encode())#默认utf-8
print(msg.encode().decode()) print(msg.encode('gbk'))
print(msg.encode('gbk').decode('gbk'))
运行结果如下:
b'\xe4\xbd\xa0\xe5\xa5\xbd'
你好
b'\xc4\xe3\xba\xc3'
你好