python2和3的一些区别,编码方式
python2与python3的区别:
print() print'abc'
#range() xrange()生成器
#raw_input()
#python3
#print('abc')
#range()
#input()
编码方式:
ascii A: 8位 1个字节
unicode A: 32位 4个字节
中: 32位 4个字节
utf-8 A: 8位 1个字节
中: 24位 3个字节
gbk A: 8位 1个字节
中: 16位 2个字节
1,各个编码之间的二进制是不能相互识别的
2,文件的储存,传输,不能是unicode
python3:
str在内存中是unicode编码的,bytes类型
对于英文:
str:
表现形式:s=“alex”
编码形式:unicode
bytes:表示形式:s=b“alex”
对于中文:
str:
表示形式:s=“中国”
编码形式:unicode
bytes:表现形式:
encode 编码 如何将str-----bytes