Python中使用items()方法返回字典元素对的教程

yipeiwu_com7年前Python基础

 items()方法返回字典的(键,值)元组对的列表
语法

以下是items()方法的语法:

dict.items()

参数

  •     NA

返回值

此方法返回元组对的列表。
例子

下面的例子显示了items()方法的使用。

#!/usr/bin/python

dict = {'Name': 'Zara', 'Age': 7}

print "Value : %s" % dict.items()

当我们运行上面的程序,它会产生以下结果:

Value : [('Age', 7), ('Name', 'Zara')]

相关文章

Python pandas.DataFrame调整列顺序及修改index名的方法

1. 从字典创建DataFrame >>> import pandas >>> dict_a = {'user_id':['webbang','w...

Python Threading 线程/互斥锁/死锁/GIL锁

导入线程包 import threading 准备函数线程,传参数 t1 = threading.Thread(target=func,args=(args,)) 类继承线程,创建线程对...

对python numpy数组中冒号的使用方法详解

对python numpy数组中冒号的使用方法详解

python中冒号实际上有两个意思:1.默认全部选择;2. 指定范围。 下面看例子 定义数组 X=array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[1...

python的一些加密方法及python 加密模块

1base64 Python内置的base64模块可以实现base64、base32、base16、base85、urlsafe_base64的编码解码,python 3.x通常输入输出...

Python线程池模块ThreadPoolExecutor用法分析

本文实例讲述了Python线程池模块ThreadPoolExecutor用法。分享给大家供大家参考,具体如下: python3内置的有Threadingpool和ThreadPoolEx...