Python Basics-Unzip sequence

Source: Internet
Author: User

Decompression sequence

Example 1: The left value must be the same as the value on the right one by one, or it will be an error

1 >>> a,b,c={1,2,3}  #a =1,b=2,c=32 >>> a3 14 >>> b5 26 >>> C7 3

Example 2: The left value must be the same as the value on the right one by one, or it will be an error

1>>> a,b,c,d,e='Hello'   #decompression sequence, the left value must be the right value is one by one corresponding to the relationship, or will error2>>>a3 'h'4>>>b5 'e'6>>>C7 'L'8>>>D9 'L'Ten>>>e One 'o'

Example 3:

Take the first and last value of a list

1 >>> l=[10,3,2,3,5,1,2,3,5,8,9]2 >>> a,*_,c=l   #取第一个值和最后一个值  3 >>> a4 5 >>> C6 9

Example 4:

The value of a, B interchange position

1 # the value of a, B interchange position 2 3 >>> a=1 4 >>> b=2 5  6 >>> x=a  7 >&G t;> x  8 1 9 >>> a=b >>> b=x  One >>> a b (2, 1)

Example 5: Exchanging values for F1 and F2

1 # exchanging values for F1 and F2 2 3 >>> f1=1 4 >>> f2=2 5  6  7 >>> f1,f2=f2,f1< /c9> 8 >>> F1  9 2 >>> f2 1

Python Basics-Unzip sequence

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.