为什么会这样?我真的不明白:
>>> P = [ [()]*3 ]*3
>>> P
[[(), (), ()], [(), (), ()], [(), (), ()]]
>>> P[0][0]=1
>>> P
[[1, (), ()], [1, (), ()], [1, (), ()]]
Run Code Online (Sandbox Code Playgroud) 来自某事的引用:
>>> 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只能返回一个值.
我知道有关元组拆包的内容,但是这个赋值是什么,你在一行上有多个等号?一个啦a = b = True
当RHS可变时,它总是让我感到沮丧,但我在找到正确的关键词以便在文档中搜索时遇到了麻烦.
当我在代码中出现错误时,我正在使用python中的队列,即使代码看起来非常完美,但后者当我改变了赋值样式时,代码开始工作.代码之前看起来像这样.
x=y=Queue()
x.put("a")
x.put("b")
print y.get()
Run Code Online (Sandbox Code Playgroud)
后来我改为这个,它开始工作了
x=Queue()
y=Queue()
x.put("a")
x.put("b")
print y.get(10)
Run Code Online (Sandbox Code Playgroud)
为什么两个代码的工作方式不同