python编码

str -> bytes 映射关系 , str->bytes可以通过 str(s,encoding='utf-8' ),   bytes->str可以通过 bytes(s,encoding='utf-8' )

bytes 本质是二进制码,例如 s=u'中华',对应的bytes是:b'\xe4\xb8\xad\xe5\x8d\x8e',一个汉字是三个字节

str 本质是指定的映射值,通过 \xe4\xb8\xad\xe5\x8d\x8e 可以得到 ‘ 中华’

 

encode:编码,由unicode转化为其他编码 如'gbk','gb2312',  s.encode('gbk')

decode 解码,由其它字符集转为 unicode, 例如  s.decode('utf-8')

posted on 2018-05-21 17:40  探无止境  阅读(114)  评论(0编辑  收藏  举报

导航