Python Variable Exchange

Source: Internet
Author: User

1 #coding = Utf-82 3A, B = 1, 24 Print 'before change'5 PrintA, B6 7A, B =B, a8 Print ' after change'9 PrintA, BTen  One #>>> A #before change - #1 2 - # after change the #2 1

Understanding Line 7th A, B = B, A is the key.

You can assign B, a to a variable C, and then print C out to see:

1 c = B, a2print  c34#   5#(2, 1)

Originally, the assignment number to the right of B, a formed a tuple. Looking at how to define a tuple, you will find that C = B, A is one of the ways to define a tuple, and C = (b, a) are also defined as a tuple.

So a, B = B, a can be understood as a, B = (b, a), then it becomes a tuple unpacking problem.

Python Variable Exchange

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.