multiple-assignment Questions
5
Solved
Is there any way to perform multiple assignment in JavaScript like this:
var a, b = "one", "two";
which would be equivalent to this:
var a = "one";
var b = "two";
Eagre asked 16/7, 2016 at 13:43
2
In python you can do something like this:
x,y = 1,2
or
x,y = function_that_returns_two_elements()
I was trying to do something similar in R but found no solution. Is it possible?
Harmonize asked 11/3, 2022 at 20:5
11
Solved
Suppose we have:
>>> x = 1
>>> y = 2
If we try assigning both values at once like so:
>>> x, y = y, x+y
>>> x
2
>>> y
3
Then we get a different result...
Sayette asked 4/1, 2012 at 10:57
1
Solved
I only just noticed that this is valid PowerShell code:
PS> $first, $rest = @(1, 2, 3)
This statement puts the first item in the array in $first and the remaining items in $rest.
PS> $fir...
Zsolway asked 9/6, 2016 at 18:35
3
Solved
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) #T...
Butchery asked 8/2, 2016 at 16:56
3
Solved
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}
...
Approbation asked 1/12, 2015 at 16:53
1
Solved
I've come across these variations when seeing multiple variables getting assigned at once:
x,y,z = 1,2,3
(x,y,z) = 1,2,3
x,y,z = (1,2,3)
(x,y,z) = (1,2,3)
I tested these and they all seem to assig...
Guenevere asked 27/4, 2015 at 3:45
1
© 2022 - 2024 — McMap. All rights reserved.