Home  >  Article  >  Backend Development  >  python advanced programming

python advanced programming

巴扎黑
巴扎黑Original
2017-06-23 16:32:102584browse

1.==, the use of is

Summary

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

·== is to compare whether two objects are equal.

2. Deep copy, shallow copy

1.Shallow copy

Shallow copy is a top-level copy of an object

The popular understanding is: copy There is a reference, and the content is not copied

2. Deep copy

Deep copy is for all levels of an object Copy (recursion)


Further understanding of copy
#3. Other ways of copying

Shallow copy pair The copy of immutable types and mutable types is different

##·The sharding expression can assign a sequence

·The copy method of dictionary can copy a dictionary

·Some built-in functions can generate a copy (list)

·Copy function in the copy module

3. Property property

1. Add getter and setter methods to private properties

2. Use property to upgrade the getter and setter methods

Running results:
Running result:
3. Use property replaces getter and setter methods

@property becomes a property function, which can make necessary checks when assigning properties and ensure that the code is clear and short. It has two main functions

·Convert methods Read-only

·Re-implement the setting and reading methods of an attribute, which can be used for boundary determination

##Running results:

Run results:

If you encounter any problems during the learning process or want to obtain learning resources, Welcome to join the learning exchange group
626062078, let’s learn Python together!

The above is the detailed content of python advanced programming. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn