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:
时间: 2024-10-18 09:02:19