Python 字典
#!/usr/bin/env python # -*- coding:utf-8 -*- # 字典dict ,由 键值对 组成, 列表和字典不可作为键,可以索引、修改,但不可切片 dic = { 'key1': 123, 'key2': '面朝大海', 'key3': True, 'key4': ['落俗', 12, 35, ], 'key5': ('asd', 45, '63',), 321: 'key', True: '真' } print(dic) # # 索引 键所对应的值 # info = dic['key2'] # print(info) # for循环可以输出键keys、值values、键值对items # for elem in dic.items(): # print(elem) ## 创建一个拥有相同的值的字典 # v = dict.fromkeys(['key1',20],56) # print(v) ## 取值 get # v = dic.get('key2') # print(v)