命令项()和命令迭代项()之间有什么区别?.之间有什么适用的区别吗?dict.items()和dict.iteritems()?来自Python文档:dict.items()*返回a复制字典的(键,值)对的列表。dict.iteritems()*返回迭代器在字典的(键,值)对上。如果我运行下面的代码,每个代码似乎都会返回对同一个对象的引用。有什么细微的差异,我错过了吗?#!/usr/bin/pythond={1:'one',2:'two',3:'three'}print 'd.items():'for k,v in d.items():
if d[k] is v: print '\tthey are the same object'
else: print '\tthey are different'print 'd.iteritems():' for k,v in d.iteritems():
if d[k] is v: print '\tthey are the same object'
else: print '\tthey are different'产出:d.items():
they are the same object
they are the same object
they are the same object
d.iteritems():
they are the same object
they are the same object
they are the same object
添加回答
举报
0/150
提交
取消