day 7 编码
1 menu = { 2 '北京': { 3 '朝阳': { 4 '国贸': { 5 'CICC': {}, 6 'HP': {}, 7 '渣打银行': {} 8 }, 9 '望京': { 10 '陌陌': {}, 11 '奔驰': {} 12 } 13 }, 14 '海淀': { 15 '五道口': { 16 '谷歌': {}, 17 '网易': {}, 18 '快手': {} 19 }, 20 }, 21 '昌平': {} 22 }, 23 '上海': { 24 '浦东': { 25 '陆家嘴': {'CICC'}, 26 '高盛': {} 27 }, 28 '闵行': {} 29 } 30 } 31 32 current_layer = menu 33 back = True 34 father_list = [] 35 while back: 36 for i in current_layer: 37 print(i) 38 choice = input('>>:').strip() 39 if len(choice) == 0: 40 continue 41 if choice in current_layer: 42 father_layer = current_layer 43 father_list.append(father_layer) 44 current_layer = current_layer[choice] 45 elif choice == "q": 46 back = False 47 print("退出") 48 else: 49 if father_list: 50 current_layer = father_list.pop()
if的使用使用多个的时候会出现问题,应使用elif
1 -------->ASCII :只能存英文和拉丁字符。一个字符占一个字节:8bite 2 -----------> gb2312:只能6700多个中文,1980年 3 ----------------> gbk1.0:存了2万多字符,1995 4 ------------------> gb18030:2000, 27000中文 5 6 ----------->unicode:utf-32: 一个字符占4字节 7 ----------->unicode:utf-16: 一个字符占2个字节或2个以上,65535 8 ----------->unicode:utf-8:一个英文用ASCII码来存,一个中文占3个字节
1 python 2中 2 a = "你好" 3 a_to_unicode = a.decode("utf-8") # 所有的解码都是解码到unicode,将utf-8的编码改为unicode,空的时候是python默认编码 4 a_to_gbk = a_to_unicode.encode("gbk") # 编码是unicode转化为gbk 5 6 python 3 7 # python 3 默认的编码方式是unicode,所有可以直接进行编码 8 a = "特斯拉" 9 a_to_gbk = a.encode("gbk") # 将unicode文件编码成gbk,并且将数据转化为bytes类型 10 a_to_unicode = a_to_gbk.decode("gbk") # 将gbk转化为Unicode,并且将数据转化为str类型