Is there any difference between the variables b and *b in these two statements? If so, what is it?
(a, b, c) = 1, 2, 3
(a, *b, c) = 1, 2, 3
Is there any difference between the variables b and *b in these two statements? If so, what is it?
(a, b, c) = 1, 2, 3
(a, *b, c) = 1, 2, 3
Please check below:
>>> (a, *b, c) = 1, 2, 3
>>> a,b,c
(1, [2], 3)
>>> type(a)
<class 'int'>
>>> type(b)
<class 'list'>
>>> type(c)
<class 'int'>
You can clearly see that using *
declares b
as list.
(a, b, c) = 1, 2, 3
print(a, b, c) # Output: 1 2 3
(a, *b, c) = 1, 2, 3
print(a, b, c) # Output: 1 [2] 3