字典文字的评估顺序 [英] Evaluation order of dictionary literals
本文介绍了字典文字的评估顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
def key(): print 'key'
def val(): print 'val'
{key() : val()}
打印val, key
,即首先评估该值.这是行为
prints val, key
, i.e. the value is evaluated first. Is this behaviour
- 在python版本和实现中是否一致?
- 在任何地方都有证件吗? ( http://docs.python.org/2/reference/expressions. html#dictionary-displays 什么也没说)
- consistent across python versions and implementations?
- documented anywhere? (http://docs.python.org/2/reference/expressions.html#dictionary-displays says nothing)
推荐答案
This section of the reference manual documents the order, but claims it is different than what you are seeing: http://docs.python.org/2/reference/expressions.html#evaluation-order
在以下几行中,将按后缀的算术顺序对表达式求值:
In the following lines, expressions will be evaluated in the arithmetic order of their suffixes:
expr1, expr2, expr3, expr4
(expr1, expr2, expr3, expr4)
{expr1: expr2, expr3: expr4}
expr1 + expr2 * (expr3 - expr4)
expr1(expr2, expr3, *expr4, **expr5)
expr3, expr4 = expr1, expr2
并且有一个针对该实现的公开错误:字典显示的评估顺序与参考手册不同.
And there is an open bug against the implementation about it: Evaluation order of dictionary display is different from reference manual.
这篇关于字典文字的评估顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文