python学习02
7.字典(dic)
dic={'name':'kyle','age':'23','gender':'male'}
字典(dic)和java中的map类似,dic中存储的是(key,value)的键值对。
(1)可以用for循环取出dic的key值:
1 >>>dic={'name':'kyle','age':'23','gender':'male'} 2 >>> for x in dic: 3 ... print x 4 ... 5 gender 6 age 7 name
(2)循环取出value值:
1 >>> dic={'name':'kyle','age':'23','gender':'male'} 2 >>> for x in dic: 3 ... print dic[x] 4 ... 5 male 6 23 7 kyle
本文出自wentaokyle,转载请标明出处!谢谢!