Python学习笔记(四)
2024-10-11 23:35:05
Python学习笔记(四)
- 作业讲解
- 编码和解码
1. 作业讲解
- 重复代码瘦身
# 定义地图
nav = {'省略'}
# 现在所处的层
current_layer = nav
# 记录你去过的地方
parent_list = []
# 是否结束循环
not_quit = True
while not_quit:
for i in current_layer:
print(i)
print("输入对应项进入 | 输入 b 返回上一层 | 输入 q 退出")
choice = input(">>>:").strip()
if len(choice) == 0: continue
if choice in current_layer:
parent_list.append(current_layer)
current_layer = current_layer[choice]
elif choice == 'q':
not_quit = False
elif choice == 'b':
if len(parent_list)<1:
print("您已在最顶层!")
else:
current_layer = parent_list.pop()
else:
print("无此项!")
2. 编码和解码
- 图解编码和解码
- Python2中的编码和解码
- 默认ASCII
# -*- coding:utf-8 -*-
s = "这是汉语"
s_to_unicode = s.decode("utf-8")
unicode_to_gbk = s_to_unicode.encode("gbk")
print(s) # 结果:乱码
print(s_to_unicode) # 结果:这是汉语
print(unicode_to_gbk) # 结果:这是汉语
- Python3中的编码和解码
- 默认 Unicode
# 在python3中encode的过程会将数据转成byte类型
# 在decode解码的过程中会将byte转成字符串
最新文章
- PRINCE2的思维结构
- 泛型中? super T和? extends T的区别
- Extjs 使用图标字体来美化按钮)
- GBDT原理实例演示 2
- URAL 1346. Intervals of Monotonicity(DP)
- Oracle 客户端配置
- Java中移位操作运算符的理解
- UVa 131 - The Psychic Poker Player
- C#面试-关于const和readonly(看了一个点赞很多的帖子有感而发!)
- wxpython线程安全的方法
- Jquery实现数据双向绑定(赋值和取值),类似AngularJS
- 2017年末大总结(by一个软件开发实习生)
- 更改checkbox的默认样式
- DapperHelper 帮助类
- 涂抹mysql笔记-mysql性能调优和诊断
- mybatis枚举自动转换(通用转换处理器实现)
- C 格式化显示时间(time.h)
- 腾讯云服务器 离线安装最新稳定版MariaDB 10.2.6
- adb server is out of date ADB server didn&#39;t ACK * failed to start daemon *一种解决方式
- Java虚拟机运行时数据区