Python简单定义与使用字典dict的方法示例

yipeiwu_com6年前Python基础

本文实例讲述了Python简单定义与使用字典的方法。分享给大家供大家参考,具体如下:

#coding=utf8
print '''''
Python中的字典映射数据类型是由键值对构成。
python中字典一般以数字或者字符串作为键。
Python中字典的值可以是任意类型的Python对象,字典元素用大括号{}包裹。
'''
dicDefine={
  'Name':'ewang',
  'Age': 28,
  'Sex': 'famale',
  'BirthDay':'1998/09/1'
  }
print 'The content of dicDefind',dicDefine
print 'The keys of dicDefind',dicDefine.keys( )
print 'The values of dicDefind',dicDefine.values()
print 'The items of dicDefind',dicDefine.items()

运行结果:

更多关于Python相关内容可查看本站专题:《Python字典操作技巧汇总》、《Python字符串操作技巧汇总》、《Python常用遍历技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》及《Python入门与进阶经典教程

希望本文所述对大家Python程序设计有所帮助。

相关文章

Python中使用gzip模块压缩文件的简单教程

压缩数据创建gzip文件 先看一个略麻烦的做法   import StringIO,gzip content = 'Life is short.I use python'...

python中zip和unzip数据的方法

本文实例讲述了python zip和unzip数据的方法。分享给大家供大家参考。具体实现方法如下: # zipping and unzipping a string using th...

Python获取Windows或Linux主机名称通用函数分享

通过python的os模块获取windows或者linux主机名的通用函数。 复制代码 代码如下: #!/usr/bin/env python  #coding=utf-8&...

Python小游戏之300行代码实现俄罗斯方块

Python小游戏之300行代码实现俄罗斯方块

前言 本文代码基于 python3.6 和 pygame1.9.4。 俄罗斯方块是儿时最经典的游戏之一,刚开始接触 pygame 的时候就想写一个俄罗斯方块。但是想到旋转,停靠,消除等操...

浅谈pandas中Dataframe的查询方法([], loc, iloc, at, iat, ix)

pandas为我们提供了多种切片方法,而要是不太了解这些方法,就会经常容易混淆。下面举例对这些切片方法进行说明。 数据介绍 先随机生成一组数据: In [5]: rnd_1 = [r...