分配python字典文字:保证语义吗? [英] Assigning python dictionary literals: are the semantics guaranteed?
本文介绍了分配python字典文字:保证语义吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个简单的问题:
Python 2.6.6 (r266:84292, Aug 9 2016, 06:11:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> d = {'foo':1,'foo':2}
>>> print d
{'foo': 2}
>>> d = {'foo':2,'foo':1}
>>> print d
{'foo': 1}
因此,似乎如果我将具有重复键的字典文字分配给变量,则至少是针对此特定的python版本,它是第二个键/对.
So it seems that if I assign a dictionary literal with a duplicate key to a variable it is the second key/pair that is used, at least for this particular python version.
这种行为能得到保证吗?
Is this behaviour guaranteed?
推荐答案
查看全文