zhiqingstudy

Be a young person with knowledge and content

1、 Exchange

a=1
b=2
temp=a
a=b
b=temp
Equivalent to
a,b=b,a
In the previous sentence, the right side of the equal sign uses encapsulation, while the left side uses deconstruction

2、 Deconstruction

1. Solve the elements of linear deconstruction and assign them to other variables in order;
2. The number of variables accepted on the left should be consistent with the number of elements solved on the right.
give an example:
lst=[3,5]
first,second=lst
print(first,second)
a,*b=range(10)
#表示a=0,b=剩下的列表
a,*b,c=range(10)
#表示a=0,c=9,b=剩下的列表
a,[b,c],d=[1,[2,3],4]
Use * variable name to receive, but cannot be used alone;
It is collected by * variable names to form a list.
Discard variable
This is a convention, an unwritten provision, not a standard;
If you don't care about a variable, you can define the variable name as _;
_ It is a legal identifier, and can also be used as a valid variable. However, if it is defined as underlined, it is hoped that it will not be used unless you clearly know that the data needs to be used.
give an example:
h,*_,t=range(10)
#
"_" generally represents the variable that the user does not care about, realizing the purpose of discarding the variable
h,t

comment
head sculpture
Code:
Related

Why you shouldn't stay at a job for more than 2 years?

3 harsh facts long-distance relationships

how to keep your girlfriend interested in a long-distance relationship




Unless otherwise specified, all content on this website is original. If the reprinted content infringes on your rights, please contact the administrator to delete it
Contact Email:2380712278@qq.com

Filing number:皖ICP备19012824号