In [1]:
t = (0, 1, 2)

In [2]:
a, b, c = t

In [3]:
print(a)
print(b)
print(c)


0
1
2

In [4]:
l = [0, 1, 2]

In [5]:
a, b, c = l

In [6]:
print(a)
print(b)
print(c)


0
1
2

In [7]:
a, b = 0, 1

print(a)
print(b)


0
1

In [8]:
# a, b = t
# ValueError: too many values to unpack (expected 2)

In [9]:
# a, b, c, d = t
# ValueError: not enough values to unpack (expected 4, got 3)

In [10]:
t = (0, 1, (2, 3, 4))

In [11]:
a, b, c = t

In [12]:
print(a)
print(b)
print(c)


0
1
(2, 3, 4)

In [13]:
print(type(c))


<class 'tuple'>

In [14]:
a, b, (c, d, e) = t

In [15]:
print(a)
print(b)
print(c)
print(d)
print(e)


0
1
2
3
4

In [16]:
t = (0, 1, 2)

In [17]:
a, b, _ = t

In [18]:
print(a)
print(b)
print(_)


0
1
2

In [19]:
t = (0, 1, 2, 3, 4)

In [20]:
a, b, *c = t

print(a)
print(b)
print(c)


0
1
[2, 3, 4]

In [21]:
print(type(c))


<class 'list'>

In [22]:
a, *b, c = t

print(a)
print(b)
print(c)


0
[1, 2, 3]
4

In [23]:
*a, b, c = t

print(a)
print(b)
print(c)


[0, 1, 2]
3
4

In [24]:
a, b, *_ = t

print(a)
print(b)
print(_)


0
1
[2, 3, 4]

In [25]:
a, b = t[0], t[1]

print(a)
print(b)


0
1

In [26]:
# *a, b, *c = t
# SyntaxError: two starred expressions in assignment

In [27]:
t = (0, 1, 2)

In [28]:
a, b, *c = t

print(a)
print(b)
print(c)


0
1
[2]

In [29]:
print(type(c))


<class 'list'>

In [30]:
a, b, c, *d = t

print(a)
print(b)
print(c)
print(d)


0
1
2
[]