标签:lex 下划线 item app 分割 机器 创建 字节 压缩
1 user = { 2 ‘name‘: ‘zhiHui‘, 3 ‘age‘: 18, 4 ‘gender‘: ‘male‘ 5 }
# 打印字典里的key for item in val.keys(): print(item) # 打印字典里的values for item in val.values(): print(item) # 打印键值对 for key, value in val.items(): print(key, value)
1 user_dict = { 2 ‘k1‘: ‘value1‘, 3 ‘k2‘: {‘kk1‘: ‘vv1‘, ‘kk2‘: ‘vv2‘, ‘kk3‘: ‘vv3‘}, 4 ‘k3‘: 123, 5 ‘k4‘: [‘alex‘, ‘eric‘, [‘a‘, ‘b‘, ‘c‘], ‘张志辉‘, {‘k11‘: ‘v11‘}] 6 } 7 8 # K4下的list列表中append一个元素 9 user_dict[‘k4‘][2].append(‘dog‘) 10 print(user_dict) 11 12 # 通过索引得到其中的一个元素的value 13 n = user_dict[‘k4‘][4][‘k11‘] 14 print(n) 15 16 # 通过key更新 value 17 user_dict[‘k2‘][‘kk1‘] = ‘zhang‘ 18 print(user_dict) 19 20 # 插入key and value 21 user_dict[‘k5‘] = 7899 22 print(user_dict)
标签:lex 下划线 item app 分割 机器 创建 字节 压缩
原文地址:http://www.cnblogs.com/one-board/p/6757327.html