您的位置:首页 > 编程语言 > Python开发

python 字典items和iteritems

2015-08-10 22:28 661 查看

3.4.6 items和iteritems

说明:items以列表方式返回字典中的键值对,iteritems以迭代器对象 返回键值对儿(Python3中不再支持);

例子:
1:  >>> x

2:  {'name': 'Bill'}

3:  >>> x.items()

4:  dict_items([('name', 'Bill')])

5:

6:  #python3中不再包含iteritems

7:  >>> x.iteritems()

8:  Traceback (most recent call last):

9:    File "<pyshell#66>", line 1, in <module>

10:      x.iteritems()

11:  AttributeError: 'dict' object has no attribute 'iteritems'

12:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: