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.