Python 字典

Python 字典

字典(dictionary)是除列表以外python之中最灵活的内置数据结构类型。列表是有序的对象结合,字典是无序的对象集合。
两者之间的区别在于:字典当中的元素是通过键来存取的,而不是通过偏移存取。
字典用"{ }"标识。字典由索引(key)和它对应的值value组成

#!/usr/bin/python
# -*- coding: UTF-8 -*-
dict = {}
dict['one'] = "haha"
dict[2] = "this is two"
print dict['one']
print dict
#python3.6写法
#print('one')
#print(dict) 

输出结果:

haha
{2: 'this is two', 'one': 'haha'}
原文地址:https://www.cnblogs.com/androidsuperman/p/6673213.html