02python learning

--- --- restore content begins

Private variables

Advanced Object-Oriented

@property decorator

 Decorator when the need to pay attention to:
  1. decorator names, function names needs to be consistent.
  2. Property need to declare, write setter, the order can not be reversed
  3. If you want just a little variable is accessed can not be modified, access control may be used @Property
  4. to modify an accessor variables can build a modifier, or delete access device.

Example: input three numbers (private), and find three numbers, which try to change the two numbers

 

In python class is dynamic.

Example: create a private space can only be viewed by default when you enter the correct password in order to be modified.

_ _ Slots _ _ Magic

If we need to define a custom type object is only bind certain properties, it can be defined in a class _ _ slots _ _ to define variables. Note that _ _ slots _ _ limited only to the current class of objects into effect, sub-class does not play any role.

 

 

 

 

--- end --- restore content

Guess you like

Origin www.cnblogs.com/sunyuxin/p/11316093.html