Python学习笔记(四)

  1. 作业讲解
  2. 编码和解码

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. 编码和解码

  • 图解编码和解码

  1. 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) # 结果:这是汉语
  1. Python3中的编码和解码
  • 默认 Unicode

# 在python3中encode的过程会将数据转成byte类型
# 在decode解码的过程中会将byte转成字符串

最新文章

  1. PRINCE2的思维结构
  2. 泛型中? super T和? extends T的区别
  3. Extjs 使用图标字体来美化按钮)
  4. GBDT原理实例演示 2
  5. URAL 1346. Intervals of Monotonicity(DP)
  6. Oracle 客户端配置
  7. Java中移位操作运算符的理解
  8. UVa 131 - The Psychic Poker Player
  9. C#面试-关于const和readonly(看了一个点赞很多的帖子有感而发!)
  10. wxpython线程安全的方法
  11. Jquery实现数据双向绑定(赋值和取值),类似AngularJS
  12. 2017年末大总结(by一个软件开发实习生)
  13. 更改checkbox的默认样式
  14. DapperHelper 帮助类
  15. 涂抹mysql笔记-mysql性能调优和诊断
  16. mybatis枚举自动转换(通用转换处理器实现)
  17. C 格式化显示时间(time.h)
  18. 腾讯云服务器 离线安装最新稳定版MariaDB 10.2.6
  19. adb server is out of date ADB server didn&#39;t ACK * failed to start daemon *一种解决方式
  20. Java虚拟机运行时数据区

热门文章

  1. 201521123119《Java程序设计》第8周学习总结
  2. 201521123122 《java程序设计》 第四周学习总结
  3. 201521123106《java程序设计》第一周学习总结
  4. Akka(26): Stream:异常处理-Exception handling
  5. Hadoop的safeMode
  6. merge 语法解析
  7. 导航栏 .active激活
  8. Numpy中Meshgrid函数介绍及2种应用场景
  9. U方法
  10. mysql 时间函数 时间转换函数