1. Object-oriented
Object-Oriented is a method of understanding and abstraction of the real world, which is the product of the development of computer programming technology to a certain stage.
2. Classes (Class):
A class is an abstraction, a blueprint, a prototype for a class of objects that have the same properties. The properties of these objects are defined in the class (variables (data)), common methods
3. Objects (object):
An object is an instantiated instance of a class, a class must be instantiated before it can be called in the program, a class can instantiate multiple objects, each object can also have different properties, like human refers to everyone, each person refers to the specific object, people and people before there is a common, there are different
4. Features
Packaging
The assignment of data in a class, internal invocation is transparent to external users, which makes the class A capsule or container in which the data and methods of the class are contained.
Inherited
A class can derive subclasses, properties, methods defined in the parent class, automatic quilt class inheritance
Polymorphic
Polymorphism is an important feature of object-oriented, simple point: "An interface, a variety of implementations", refers to a base class derived from a different subclass, and each subclass inherits the same method name, but also the parent class method to do a different implementation, this is the same thing shows a variety of forms.
5. Constructors
Do some initialization work for classes at instantiation
Instance variable: SELF.A = a
Instance variable (static property), scoped to the instance itself
Example
1 classPerson :2n =123#类变量3 4 def __init__ (self,name,ability):5 #构造函数6 7Self.name =name #实例化变量 (static property), scoped to instantiate itself8Self.ability =Ability9 Ten def Eat (self): # class Method Function (dynamic property) OnePrint'I'll eat something! ') A - def run (self): -Print'I'll runing!') the - def sleep (self): -Print'I'll sleep!') - + def doing (self): -Print'I am%s'%self.ability) + AR1 = Person ('Zhang San','Dancing') at - R1.sleep () - R1.run () - r1.eat () - r1.doing () -Print (R1.N)
Results
I'll sleep! ! ! I am dancing1234
Python 3.x Learning note 9 (Object-oriented)