Classes and Objects Introduction
That class category, type, object-oriented design is the most important concept, the object is a combination of characteristics and skills, and the category is similar to a series of objects and features a combination of skills in the real world: first, the object, and then there class, object is a concrete existence, while the class is just a concept, not real # in the program, be sure that: first, the definition of class, after class generated using the object PS: 1. features used to identify variables in the program, skills to use function identification 2. thus the most common class is nothing more than: the definition of variables and functions
The definition of class
class class name:
content # class describes the attributes and skills
# description attribute with variable
# describe the behavior of a function
# First class name written specification is intended to see to know the name of the name of a big hump nomenclature
# hump word is capitalized, the big hump is the first letter capitalized, small hump is the first letter lowercase
# Note: 1. The class can have arbitrary python code that will execute in the class definition phase 2 and they may be a new name space used to store variable names and function names like, by class name .__ dict__ View 3. for the classical class for us (the new class is limited) by the name of the dictionary operations class name space, but provides us with a special python syntax 4. point is the syntax to access attributes defined in the class name, attributes are class: designed to access the property, the nature of the operation is __dict__
Attributes
Class has two attributes: data attributes and function attributes
1. The data class attribute is shared by all objects
2. The function attribute class is bound to the subject with
Properties can also be written in an object
Object properties, each object is unique
If present in the same class attribute to access the object if there is no access to the object class and
Deletions attribute change search
Increase property object variable name. Attribute name = attribute value to delete attribute del object variable name attribute name modify objects. Attribute = New Value View property access is the object of all the properties print (Object .__ dict__) class information access objects print (Object .__ class__)
Create Object
class class name:
pass
# Create Object
Object Name = class name ()
Create Object -> name space of the calling class
Also called to create an object instance of the class, the class definition of a good, can create an instance of an object class according to the class
A class can build multiple objects, each object in memory is independent
The essence of the object function is to integrate data and process the data together, so to get an object on both his function data and processing data to be processed
__init__ method
__init__ initialization method is called, is essentially a function of characteristics 1: when the object is instantiated, the init method of automatically Feature 2: automatically object as the first argument, parameter names bit self, self may be other name, but is not recommended to change the functions: user initial value assigned to the object # stressed: # 1, can have any python code within the process # 2, must not have a return value
python class built special properties
The name of the class name .__ name __ # class (string) document String class name .__ doc __ # class (comments) class name .__ first parent base __ # class class name .__ bases __ # class tuple of all the parent class consisting of class name dictionary .__ dict __ # kind attribute class name .__ __ # Module1 module where the class definition class name of class __ # .__ corresponding class instance (only the new class)
Classes and Objects Introduction
That class category, type, object-oriented design is the most important concept, the object is a combination of characteristics and skills, and the category is similar to a series of objects and features a combination of skills in the real world: first, the object, and then there class, object is a concrete existence, while the class is just a concept, not real # in the program, be sure that: first, the definition of class, after class generated using the object PS: 1. features used to identify variables in the program, skills to use function identification 2. thus the most common class is nothing more than: the definition of variables and functions
The definition of class
class class name:
content # class describes the attributes and skills
# description attribute with variable
# describe the behavior of a function
# First class name written specification is intended to see to know the name of the name of a big hump nomenclature
# hump word is capitalized, the big hump is the first letter capitalized, small hump is the first letter lowercase
# Note: 1. The class can have arbitrary python code that will execute in the class definition phase 2 and they may be a new name space used to store variable names and function names like, by class name .__ dict__ View 3. for the classical class for us (the new class is limited) by the name of the dictionary operations class name space, but provides us with a special python syntax 4. point is the syntax to access attributes defined in the class name, attributes are class: designed to access the property, the nature of the operation is __dict__
Attributes
Class has two attributes: data attributes and function attributes
1. The data class attribute is shared by all objects
2. The function attribute class is bound to the subject with
Properties can also be written in an object
Object properties, each object is unique
If present in the same class attribute to access the object if there is no access to the object class and
Deletions attribute change search
Increase property object variable name. Attribute name = attribute value to delete attribute del object variable name attribute name modify objects. Attribute = New Value View property access is the object of all the properties print (Object .__ dict__) class information access objects print (Object .__ class__)
Create Object
class class name:
pass
# Create Object
Object Name = class name ()
Create Object -> name space of the calling class
Also called to create an object instance of the class, the class definition of a good, can create an instance of an object class according to the class
A class can build multiple objects, each object in memory is independent
The essence of the object function is to integrate data and process the data together, so to get an object on both his function data and processing data to be processed
__init__ method
__init__ initialization method is called, is essentially a function of characteristics 1: when the object is instantiated, the init method of automatically Feature 2: automatically object as the first argument, parameter names bit self, self may be other name, but is not recommended to change the functions: user initial value assigned to the object # stressed: # 1, can have any python code within the process # 2, must not have a return value
python class built special properties
The name of the class name .__ name __ # class (string) document String class name .__ doc __ # class (comments) class name .__ first parent base __ # class class name .__ bases __ # class tuple of all the parent class consisting of class name dictionary .__ dict __ # kind attribute class name .__ __ # Module1 module where the class definition class name of class __ # .__ corresponding class instance (only the new class)