The concept of classes and objects

Class is a collection of things, one vote has the same properties and characteristics, as well as a template

Individual, independent of the different templates generated and the object is in line with this collection of individuals

For class, the two parts are divided into class names and class thereof: class name is the name (initials) by class statement defined; class body is a specific code content class includes the variables and methods (the class definition function) sections .

For body type, the two aspects are discussed:

Class point of view:

Use the class name .__ dict__ can view all of the content class. The return is in the form of a dictionary, the dictionary has a way of viewing, but not additions and deletions.

Class name variable name, this embodiment is universal, can CRUD ..

Methods in the project application basically do not have access to the class name using the class name to view all of the content is enough

Object angle:

1. Package constructor and

First, run the code again and class names in parentheses will create an object, a process called instantiation ... is instantiated successfully, generate an object space, occupies a corresponding memory

This space corresponds to the newly created object,

Then automatically performs class __init__ statements, and this object is assigned Self
__init__ work only usage: to the corresponding attribute object encapsulates
DEF the __init __ (Self, name, Age)
    the self.name # increase the parameter name = content name to a new space called the name

Equal right of the user name is entered in the example of the time, after packaging via the __init __ (constructor), as a property of the object

2. omnipotent point
execution ret = class name (), ret can directly use the object name to an object in a static variable additions and deletions are here CRUD change search for a property of the object #
method uses the object name of the class and static variables operation, you can call, nothing more # check here and is calling for this group in the class template can only check the
object calls all arbitrary method, you can not pass the default parameters self, the direct use of object names. class the method name () can

 

Guess you like

Origin www.cnblogs.com/shachengcc1/p/11129881.html