+ 2
I need help.what is this?
*x,y=[1,2],[3,4],[5,6], print(list(zip(*x+[y]))[1][1]) why we use *before x what is this,am getting confused.why we used this.canayone explain me this.¿
1 Respuesta
+ 5
In this case '*' means that a variable takes all the values not taken by other variables. So, in the pair of vairables x and y, y is the last and it takes the last value then *x takes all values left.
>>> *x,y=[1,2],[3,4],[5,6]
>>> x
[[1, 2], [3, 4]]
>>> y
[5, 6]
If you put the '*' before y, then y will take all the values left:
>>> x,*y=[1,2],[3,4],[5,6]
>>> x
[1, 2]
>>> y
[[3, 4], [5, 6]]