zoukankan      html  css  js  c++  java
  • Python学习笔记(四)

    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转成字符串
    
    
    以此为趣,乐在其中。
  • 相关阅读:
    面向对象的三个特征:封装(抽象)、继承、多态
    java中流程控制有4种循环,各自的适用场景
    break 和 continue
    基础知识点总结及示例
    Java程序的运行过程,以及Java为什么能够跨平台
    JDK,JRE,JVM的区别与联系?
    jsp(二)
    JSP
    过滤器
    Servlet监听器(二)
  • 原文地址:https://www.cnblogs.com/ryomahan/p/7506549.html
Copyright © 2011-2022 走看看