Python Advanced Programming

Source: Internet
Author: User

Use of 1.==,is

Summarize

is is to compare whether two references point to the same object (reference comparison).

== is a comparison of two objects for equality.

2. Deep copy, Shallow copy

1. Shallow copy

A shallow copy is a top-level copy of an object

The popular understanding is that a reference is copied and no content is copied

2. Deep copy

A deep copy is a copy (recursive) for all levels of an object


Further understanding of the copy

3. Other ways of copying

Shallow copy differs from copy of immutable type and mutable type

• A shard expression can assign a sequence of values

• The copy method of the dictionary can copy a dictionary

• Some built-in functions can generate copies (list)

copy function in the copy module

3. Property Properties

1. Adding getter and setter methods to private properties

2. Using property to upgrade getter and setter methods


Operation Result:
Operation Result:

3. Replace getter and setter methods with property

@property become a property function, you can do the necessary checks on the property assignment, and ensure that the code is clear and short, there are 2 main functions

• Convert the method to read-only

• Re-implement a property set and read method to make boundary judgments


Operation Result:
Operation Result:

You are welcome to join the Learning Exchange Group if you encounter any problems or want to acquire learning resources in the learning process.
626062078, we learn python! together.

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.