The difference between the Python assignment operator and the enhanced assignment operator

Source: Internet
Author: User

A operator= B is not exactly the same as a = a operator B, except that:

1, the former only query the value of a once, and thus have a faster possibility.

2. If a is a complex expression (for example, the index position of a list is computed, such as Items[offset + index), the latter is less error when using the enhanced assignment operator. This is because if the calculation process needs to change, then the maintainer only has to change it once, not two times.

3, Python overloads the operator + and + =, respectively, for strings and lists, the former represents a connection, the latter represents appending strings and extending.

When used, select the appropriate operator based on the usage scenario.

----The Python3 Program Development Guide. Second edition of Reading notes

The difference between the Python assignment operator and the enhanced assignment operator

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.