In [1]:
t = (0, 1, 2)
In [2]:
a, b, c = t
In [3]:
print(a)
print(b)
print(c)
In [4]:
l = [0, 1, 2]
In [5]:
a, b, c = l
In [6]:
print(a)
print(b)
print(c)
In [7]:
a, b = 0, 1
print(a)
print(b)
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)
In [13]:
print(type(c))
In [14]:
a, b, (c, d, e) = t
In [15]:
print(a)
print(b)
print(c)
print(d)
print(e)
In [16]:
t = (0, 1, 2)
In [17]:
a, b, _ = t
In [18]:
print(a)
print(b)
print(_)
In [19]:
t = (0, 1, 2, 3, 4)
In [20]:
a, b, *c = t
print(a)
print(b)
print(c)
In [21]:
print(type(c))
In [22]:
a, *b, c = t
print(a)
print(b)
print(c)
In [23]:
*a, b, c = t
print(a)
print(b)
print(c)
In [24]:
a, b, *_ = t
print(a)
print(b)
print(_)
In [25]:
a, b = t[0], t[1]
print(a)
print(b)
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)
In [29]:
print(type(c))
In [30]:
a, b, c, *d = t
print(a)
print(b)
print(c)
print(d)