解码 decode
回忆上次内容
- 最早也指电报码
- 后来有各种编码、密码、砝码、条码
- 都指的是把各种事物编个号
![[oeasy]python0017_解码_decode_字节序列_bytes_字符串_str_第1张图片](http://img.e-com-net.com/image/info8/9d0eea659f8f4d22a560263b0c8259fa.jpg)
- 给事物编号就是编码
- 怎么通过编号找到原来的事物呢?
解码
- 这次扫到号知道是白菜
- 扫到码就知道这个条码
- 对应这个大白菜并知道价格
![[oeasy]python0017_解码_decode_字节序列_bytes_字符串_str_第2张图片](http://img.e-com-net.com/image/info8/ea2e0f7bcf07402a8aab516a15f898f2.jpg)
解码(decode)
- defuse 解除保险炸弹引信
- decolor 漂白
- defame 中伤
- destruct 破坏
- demodulation 解调制
![[oeasy]python0017_解码_decode_字节序列_bytes_字符串_str_第3张图片](http://img.e-com-net.com/image/info8/a8e506789c1c4ca4b1b62ea326cd2ce6.png)
编解码
![[oeasy]python0017_解码_decode_字节序列_bytes_字符串_str_第4张图片](http://img.e-com-net.com/image/info8/80d557f11175425d872248d93a9a8f72.jpg)
- str(字符串)
'a'
encode(编码)之后
![[oeasy]python0017_解码_decode_字节序列_bytes_字符串_str_第5张图片](http://img.e-com-net.com/image/info8/8a410afd21fa4ba9b244c1f555e55261.jpg)
- bytes(字节序列)
b'\x61'
decode(解码)之后
- 编码(encode) 和解码(decode) 互为逆运算
- 很像
编码解码
- 可以先编码再解码
- 也可以先解码再编码
- 绕来绕去
- 也没做神马
![[oeasy]python0017_解码_decode_字节序列_bytes_字符串_str_第6张图片](http://img.e-com-net.com/image/info8/7b1cee50b2a4499d9ee6a1aa1537ca46.jpg)
- 掌握这个基础是最起码
- 基本功要练得硬桥硬马
- 实战方能稳扎稳打
- 否则以后各种乱码
![[oeasy]python0017_解码_decode_字节序列_bytes_字符串_str_第7张图片](http://img.e-com-net.com/image/info8/47028dfc810a435bbea0255214635b6e.jpg)
闭环
![[oeasy]python0017_解码_decode_字节序列_bytes_字符串_str_第8张图片](http://img.e-com-net.com/image/info8/81384551b3164e199477236258ef7cc0.jpg)
![[oeasy]python0017_解码_decode_字节序列_bytes_字符串_str_第9张图片](http://img.e-com-net.com/image/info8/37097b5e9cff47659bc53843c38459ad.jpg)
解码
![[oeasy]python0017_解码_decode_字节序列_bytes_字符串_str_第10张图片](http://img.e-com-net.com/image/info8/094f74dc79db4816b14c926ec5cfe827.jpg)
help(bytes.decode)
help(b"a".decode)
![[oeasy]python0017_解码_decode_字节序列_bytes_字符串_str_第11张图片](http://img.e-com-net.com/image/info8/f023d65c5d874b75b00d246d7d0058fb.jpg)
图像编码
![[oeasy]python0017_解码_decode_字节序列_bytes_字符串_str_第12张图片](http://img.e-com-net.com/image/info8/62a024b3c79d4dc4ba5cd003132a6b34.png)
![[oeasy]python0017_解码_decode_字节序列_bytes_字符串_str_第13张图片](http://img.e-com-net.com/image/info8/2ae239c6f6894cf3b409dfae3a503293.jpg)
大小字母差值
-
0x61-0x7A
这个范围是小写字母
-
0x41-0x5A
这个范围是大写字母
#输出a的ASCII码
ord("a")
#输出A的ASCII码
ord("A")
#输出大小写之差
ord("a")-ord("A")
#差值的16进制形式
hex(ord("a")-ord("A"))
#差值的2进制形式
bin(ord("a")-ord("A"))
- 大写字母和小写字母相差(
32
)10进制
![[oeasy]python0017_解码_decode_字节序列_bytes_字符串_str_第14张图片](http://img.e-com-net.com/image/info8/404ea2b9e65746428c4d2984f0ee0df5.jpg)
- 为什么不多不少
- 就差 (
32
)10进制
- 怎么那么寸呢?
- 先去总结一下
总结
- encode 编码
- decode 解码
- 互为逆过程
- 大小写字母之间序号全都相差(
32
)10进制
![[oeasy]python0017_解码_decode_字节序列_bytes_字符串_str_第15张图片](http://img.e-com-net.com/image/info8/6a3ebd3df5fd47dca2c24c2f1bc6f0d3.jpg)
- 这是为什么呢?
- 我们下次再说
- 蓝桥->https://www.lanqiao.cn/teacher/3584
- github->https://github.com/overmind1980/oeasy-python-tutorial
- gitee->https://gitee.com/overmind1980/oeasypython
- 视频->https://www.bilibili.com/video/BV1CU4y1Z7gQ 作者:oeasy