1、遍历字典
for key in dict:
key:dict[key]
2、输出字典指定key的value
dict[‘key‘]
dict[‘key1‘][‘key2‘][‘key3‘]嵌套字典
3、字典常用方法:
4、列表常用方法:
1 # -*- coding:utf-8 -* 2 game_gid = [‘wzry‘, ‘hpjy‘, ‘yltd‘, ‘yxlm‘, ‘jdqs‘, ‘sjyx‘, ‘stu1{}‘] 3 person = { 4 ‘name‘: ‘小明‘, 5 ‘math‘: ‘90‘, 6 ‘chinese‘: ‘98‘, 7 ‘english‘: ‘100‘, 8 ‘stu2‘: { 9 ‘name‘: ‘小虹‘, 10 ‘math‘: ‘87‘, 11 ‘chinese‘: ‘85‘, 12 ‘english‘: ‘99‘, 13 }, 14 ‘stu2‘: { 15 ‘name‘: ‘李丽‘, 16 ‘math‘: ‘99‘, 17 ‘chinese‘: ‘90‘, 18 ‘english‘: ‘86‘, 19 } 20 } 21 # 循环打印出字典key、value 22 for key in person: 23 print(f‘{key}:{person[key]}‘) 24 25 # 循环打印出列表值 26 for gid in game_gid: 27 print(gid) 28 29 # 嵌套字典 30 print(person[‘stu2‘][‘math‘])
原文:https://www.cnblogs.com/spritegirl/p/14838578.html