相关疑难解决方法(0)

链式作业如何运作?

来自某事的引用:

>>> x = y = somefunction()
Run Code Online (Sandbox Code Playgroud)

是相同的

>>> y = somefunction()
>>> x = y
Run Code Online (Sandbox Code Playgroud)

问题:是

x = y = somefunction()
Run Code Online (Sandbox Code Playgroud)

同样的

x = somefunction()
y = somefunction()
Run Code Online (Sandbox Code Playgroud)

根据我的理解,它们应该是相同的,因为somefunction只能返回一个值.

python python-3.x

29
推荐指数
5
解决办法
9479
查看次数

Python赋值运算符优先级 - (a,b)= a [b] = {},5

我在Twitter上看到了这个Python片段,并且对输出感到非常困惑:

>>> a, b = a[b] = {}, 5
>>> a
{5: ({...}, 5)}
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?

python variable-assignment

25
推荐指数
1
解决办法
816
查看次数

标签 统计

python ×2

python-3.x ×1

variable-assignment ×1