Python学习笔记021
编码解码
编码(encode):将Unicode字符串(中的代码点)转换特定字符编码对应的字节串的过程和规则
解码(decode):将特定字符编码的字节串转换为对应的Unicode字符串(中的代码点)的过程和规则
encode unicode to any code
decode any code to unicode
python3 默认 unicode
encode 在编码的同时,把数据转化成bytes
decode 在解码的同时,把bytes转化成字符串
s='中国'
s2g=s.encode('gbk')
g2u=s2g.decode('GBK')
print(s,s2g,g2u)