python:编码

 

unicode :万国码
A : 0000 0001 0000 0001 0000 0001 0000 0001 32位
中: 0000 0101 0000 0001 0000 0001 0000 0001 32位

升级:utf-8 :用最少8位表示一个字符
A : 0000 0001 8位
欧洲 : 0000 0001 0000 0001 16位
亚洲 中 : 0000 0101 0000 0001 0000 0001 24位

gbk :国标
a : 0000 0001 8位
中 : 0000 0101 0000 0001 16位
1,不同编码之间是不能互相识别对方的二进制,会报错,或者产生乱码.
2,在你的字符串(文件),存储,传输时,必须使用非unicode的二进制(01010101).
py3:
字符串:编码方式(在内存中的运行方式):默认都是unicode.

int

byte
对于非中文: 表现形式: b'alex'
内部编码: utf-8 gbk,gb2312...(非unicode) 你设定的.

对于中文: 表现形式: b'xe3\xf2\x36\xe3\xf2\x36\'
内部编码: utf-8 gbk,gb2312...(非unicode) 你设定的.

str
对于非中文: 表现形式: 'alex'
内部编码: unicode
对于中文: 表现形式: '中国'
内部编码: unicode


#encode 编码 , 如何将str --> bytes,()
s1 = 'alex'
s2 = s1.encode('utf-8')#括号中也可以写成别的编码类型
print(s2)

s3 = '中国'
s4 = s3.encode('utf-8') 将s3转化成 以utf-8的形式 转化为:bytes 数据类型
print(s4)

 

posted @ 2018-10-09 15:45  是我是我还是我  阅读(80)  评论(0)    收藏  举报