0 advanced application of python-10.1 sequence assignment in basic science

Source: Internet
Author: User

The basic operation of an assignment statement has already been mentioned in the previous chapters, so let's say assignment to advanced applications

The first section is about sequence assignment.


Above is a simple sequence decomposition assignment statement, note: In the third row c,d=a,b is actually composed of a tuple, the right value is assigned to the left variable

The above-mentioned tuple usage techniques are often used

Moreover, the above technique is not only suitable for the entire tuple, but also suitable for partial assignment


Advanced Sequence Assignment Statement pattern

We can use = to mix the sides together, but the number of elements on the right must be the same as the left.

>>> a,b,c,d= ' ABCD ' >>> a,b,c,d (' A ', ' B ', ' C ', ' d ') >>> a,b,c= ' ABCD ' Traceback (most recent call Last):  File ' <pyshell#20> ', line 1, in <module>    



Sequence expansion pack

In the above we see that the left and right sides of the number must be the same, but there are other ways to break this

We can use * as a wildcard to represent the remaining data items

The above a is just the first item, the rest is assigned to B

Similarly:


This sequence extension package is valid for all sequence types


Note that there is a boundary condition where Python automatically assigns an empty value to an item that is out of bounds


It is also important to note that the * symbol can only have one, and only one variable is not available *
>>> a,*b,*c,d,*e= ' ABCD ' Syntaxerror:two starred expressions in assignment>>> a,b,c,d,e= ' ABCD ' Traceback (most recent):  File "<pyshell#46>", line 1, in <module>    


If a variable needs to be added *, then the variable must be followed by a comma, followed by an empty variable


Right here, thank you.

------------------------------------------------------------------

Click to jump 0 basic python-Catalogue






Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

0 advanced application of python-10.1 sequence assignment in basic science

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.