为了账号安全,请及时绑定邮箱和手机立即绑定

命令项()和命令迭代项()之间有什么区别?

命令项()和命令迭代项()之间有什么区别?

RISEBY 2019-07-02 15:03:48
命令项()和命令迭代项()之间有什么区别?.之间有什么适用的区别吗?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
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 434 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信