转化为10进制
回忆上次内容
- 上次 把其他进制
- 转化回
十进制
- 用的是 int 函数
- int 来自于 integer
- 同源词 还有
- integrate
- entire
- 意思都是
完整的
完整的 和 零散的
- 相对
- 可以把
零散的小数
- 转化为
完整的整数吗?🤔
取整
- 可以 把一个浮点型的小数 取整
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_浮点型](https://file.cfanz.cn/uploads/png/2023/01/14/9/e6HaJe9Z30.png)
- 取整 可能会造成
- 运算结果的 不同
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_进制_02](https://file.cfanz.cn/uploads/png/2023/01/14/9/J5B4708ZC6.png)
- 3.3 是 一个浮点型 的 小数
- 现在 把他当做 一个
整数
- 这个过程叫做cast
cast
- cast原意是投掷
- cast a spell 施法 投一个咒语
- cast a vote 投票
- cast 铸造 把铁水投入到磨具中
- plaster cast 铸造石膏
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_浮点型_03](https://file.cfanz.cn/uploads/png/2023/01/14/9/bD0Dc3S97F.png)
投影
- cast a shadow 投上一层阴影
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_进制_04](https://file.cfanz.cn/uploads/png/2023/01/14/9/9F2beO4Zc8.png)
- 扮演成
- 手经过 cast 成为鹿
- 人扮演成其他的角色
演员表
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_进制_05](https://file.cfanz.cn/uploads/png/2023/01/14/9/1M7478646c.png)
- 一部戏的全体演员
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_字符串_06](https://file.cfanz.cn/uploads/png/2023/01/14/9/8636X4H5J3.png)
- 数据类型的转化也是一种扮演
cast
- 我们 让
3.3
- 扮演(cast)了
-
3这样一个角色
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_浮点型_07](https://file.cfanz.cn/uploads/png/2023/01/14/9/100W66S1B0.png)
- 甚至可以让
π
- 扮演
-
3这个角色
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_字符串_08](https://file.cfanz.cn/uploads/png/2023/01/14/9/aQG8SP3J08.png)
字符串
- 还可以 让字符串
"3"
- 扮演 整数
3 这个角色
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_浮点型_09](https://file.cfanz.cn/uploads/png/2023/01/14/9/1I8O0S70D1.png)
- 但无法让
- 字符串"3.3"
- 扮演 整数
3 这个角色
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_字符串_10](https://file.cfanz.cn/uploads/png/2023/01/14/9/c6EbZ690Kc.png)
- 居然能 让
3.9
- 扮演 整数
3 这个角色?
查看文档
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_字符串_11](https://file.cfanz.cn/uploads/jpeg/2023/01/14/9/0ad4DcWaE8.jpeg)
- 把 浮点型(float)的 3.9
- 小数部分 截掉(truncates)
- 转化为 整型(int)的 3
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_浮点型_12](https://file.cfanz.cn/uploads/png/2023/01/14/9/bW0M4bZd7I.png)
- cast
- 将 某种数据类型的表达式
- 显式转换 为 另一种数据类型
- 可以将<kbd>tab</kbd>键 转化为整数吗?
tab 键
- <kbd>tab</kbd> 是一个按键
- 试着 求出<kbd>tab</kbd>键对应 的 ascii序号
- 也就是
\t 对应的数值
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_浮点型_13](https://file.cfanz.cn/uploads/png/2023/01/14/9/E8EK624cTc.png)
- 求出这个数值对应的
- 2 进制
- 8 进制
- 10 进制
- 16 进制
- 然后尝试
- 用数值的方式输出<kbd>tab</kbd>
- 不要翻页
转化与输出
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_浮点型_14](https://file.cfanz.cn/uploads/png/2023/01/14/9/1d41GY8OY2.png)
- 可以找到
- <kbd>tab</kbd>序号的 各种形式
- 然后 输出
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_字符串_15](https://file.cfanz.cn/uploads/png/2023/01/10/14/3HIS6761W7.png)
- 可以来 一个循环吗?
- 就是
- 一顿操作猛如虎
- 仔细一看原地杵
- 那种
绕回来
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_浮点型_16](https://file.cfanz.cn/uploads/png/2023/01/14/9/JL6R38d3X7.png)
- 可以 反过来
- 绕一圈 吗?
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_进制_17](https://file.cfanz.cn/uploads/png/2023/01/14/9/2a87d45d26.png)
反向绕
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_字符串_18](https://file.cfanz.cn/uploads/png/2023/01/14/9/5dea7b08eD.png)
- 可以 把二进制形式转化为十六进制 吗?
转化
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_浮点型_19](https://file.cfanz.cn/uploads/png/2023/01/14/9/3534KZ213H.png)
- 东西 还是那个东西
- 状态 可以随意流转的
![图片描述 [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符_浮点型_20](https://file.cfanz.cn/uploads/png/2023/01/14/9/f1L8a6016Q.png)
- 转化过程中 始终要注意类型
- 如果 不确定类型的话
- 用type函数 确认一下
总结
- 这次在各种类型间不断转化
- int 整型数字
- float 浮点型数字
- str 字符串
- 最后温习了 转义字符
\t 类似的还有
-
\n -
\r
- 还有 通过数字 得到ascii字符
-
\ooo -
\xhh
- 如果
- 我想
只输出 \ 这个字符
- 可以吗?
-
\ 叫什么字符来着?🤔
- 我们下次再说!👋
- 蓝桥->https://www.lanqiao.cn/courses/3584
- github->https://github.com/overmind1980/oeasy-python-tutorial
- gitee->https://gitee.com/overmind1980/oeasypython
- 视频->https://www.bilibili.com/video/BV1CU4y1Z7gQ 作者:oeasy

