multiple-assignment

Python3 multiple assignment and memory address [duplicate]

左心房为你撑大大i 提交于 2020-01-09 10:40:09
问题 This question already has answers here : 'is' operator behaves unexpectedly with non-cached integers (2 answers) Closed 3 years ago . After reading this and this, which are pretty similar to my question, I still cannot understand the following behaviour: a = 257 b = 257 print(a is b) #False a, b = 257, 257 print(a is b) #True When printing id(a) and id(b) I can see that the variables, to which the values were assigned in separate lines, have different ids, whereas with multiple assignment

Multiple assignment confusion

故事扮演 提交于 2019-11-28 23:23:05
I understand that the assignment operator is right associative. So for example x = y = z = 2 is equivalent to (x = (y = (z = 2))) That being the case, I tried the following: foo.x = foo = {a:1} I expected that the object foo would be created with value {a:1} and then the property x will be created on foo which will just be a reference to the foo object. (This is actually what happens if I was to separate the multiple assignment statement into two separate statements foo = {a:1};foo.x = foo; ) The outcome was actually: ReferenceError: foo is not defined(…) So then I tried the following: var foo

Python3 multiple assignment and memory address [duplicate]

让人想犯罪 __ 提交于 2019-11-28 11:10:29
This question already has an answer here: 'is' operator behaves unexpectedly with non-cached integers 2 answers After reading this and this , which are pretty similar to my question, I still cannot understand the following behaviour: a = 257 b = 257 print(a is b) #False a, b = 257, 257 print(a is b) #True When printing id(a) and id(b) I can see that the variables, to which the values were assigned in separate lines, have different ids, whereas with multiple assignment both values have the same id: a = 257 b = 257 print(id(a)) #139828809414512 print(id(b)) #139828809414224 a, b = 257, 257 print

Multiple assignment confusion

爱⌒轻易说出口 提交于 2019-11-27 14:57:14
问题 I understand that the assignment operator is right associative. So for example x = y = z = 2 is equivalent to (x = (y = (z = 2))) That being the case, I tried the following: foo.x = foo = {a:1} I expected that the object foo would be created with value {a:1} and then the property x will be created on foo which will just be a reference to the foo object. (This is actually what happens if I was to separate the multiple assignment statement into two separate statements foo = {a:1};foo.x = foo; )