C不是guarantee any evaluation order,所以像f(g1()+g2(), g3(), g4())
这样的语句可以按任何顺序执行g1()
、g2()
、g3()
、和{f()
将在它们之后执行)
那么Python呢?我对Python2.7的实验表明,它似乎是从左到右的求值顺序,但我想知道是否指定了这种情况。
测试程序:
def somefunc(prolog, epilog):
print prolog
def f(a, b, *args):
print epilog
return f
def f(text):
print text
return 1
somefunc('f1','f2')(f('hey'),f('ho'),f('hahaha'),f('tweedledee')+f('tweedledum'))
哪个指纹
^{pr2}$
https://docs.python.org/3/reference/expressions.html#evaluation-order:
The same is true in Python 2.
是的,保证从左到右的评估顺序,但作业除外。这里有记录(py2,py3):
如果语言没有对此做出选择,那么对一个参数的求值可能会改变另一个参数,并导致未指定的行为,因此Python的所有实现都必须遵循此规范
相关问题 更多 >
编程相关推荐