#!/usr/bin/env python # -*- coding:utf-8 -*- #str --->byte encode 编码 s = '二哥' b = s.encode('utf-8') print(b) #byte --->str decode 解码 s1 = b.decode('utf-8') print(s1) s = '春哥' b = s.encode('utf-8') print(b) #byte --->str decode 解码 s1 = b.decode('gbk') print(s1)//这种情况下会出现乱码,因为编码和解码对中文的处理方式有别