**Unpack **
It is called Unpacking in English, which means to take out the elements in the container one by one and put them elsewhere. It is like your parents go to the vegetable market to buy a bag of apples and send them to each member of the family. This process is unpacking. Unpacking in Python is done automatically, for example:
student =['xiaoqiang','man','22']
name,sex,age = student
print(name,sex,age)
Result: xiaoqiang man 22
If there are 3 elements in the list, they can be assigned to 3 variables. In addition to list objects that can be unpacked, any iterable object supports unpacking. Iterable objects include tuples, dictionaries, sets, strings, generators, etc., all objects that implement the next method.
Knowledge point expansion:
Sequence unpacking example:
a, b, c =1,2,3
a
1
b
2
c
3
Nested unpacking example
( a, b),(c, d)=(1,2),(3,4)
a
1
b
2
c
3
d
4
a, b, c,d(1,2,3,4)
So far this article on the summary of Python unpacking knowledge points is introduced. For more detailed explanations of Python unpacking, please search for ZaLou.Cn's previous articles or continue to browse related articles below. I hope you will support ZaLou more in the future. Cn!
Recommended Posts