As usual, the original chain http://www.cnblogs.com/vamei/archive/2012/06/02/2531515.html
#第一次接触面向对象, and there is no basis for C # say a long time did not go to see C's Tutorial # Remember C teacher said, object-oriented, process-oriented, not very easy to understand, understand the process-oriented, naturally understand what is object-oriented (here are reported, right not to delve into) #这里接触到了attribute, Previously encountered error is to skip as a workaround, after the next # The author defines the bird's class, and the property # class: The property of similar things; Bird # attribute attribute: The characteristics of birds, bird's properties, feathers, oviparous to multiply # New classes, mammals, breathing with lungs, Birth class Bird (object): Have_feather = true# Feather is true way_of_reproduction = ' egg ' #繁衍方式蛋summer = Bird () print (' Summer.way_o F_reproduction is ', summer.way_of_reproduction) #输出结果: Summer.way_of_reproduction is egg# added action to differentiate between dynamic and static items class bird ( Object): # () is an object that indicates that the class has no parent class, the head is Have_feather = True way_of_reproduction = ' egg ' def move (self, dx, dy): #这里定义, SEL f The problem, the author did not explain that DX dy should be able to use X y instead of, d prefixes do not know what the author is trying to express what position = [0, 0] #位置的坐标, through the list implementation, why through the list? Position[0] = position[0] + dx# by index, update list position[1] = position[1] + dy# same return position# back to updated Listsumm ER = Bird () print (' After move: ', Summer.move (5, 8)) #summer移动后的位置 # output: After move: [5, 8] #self question the author says, in order to make it easier to refer to the object itself, This sentence is also not understood # and then extends out of the subclass # Subclasses are Class chicken (bird) inherited from the parent class: #定义bird () Inside is object, now ()Polygons are bird, stating that chicken is a subclass of bird, chicken is the bird of inheritance Way_of_move = ' walk ' #移动方式是走 POSSIBLE_IN_KFC = true# may see class Oriole at KFC ( Bird): #同上 way_of_move = ' Fly ' #移动方式是飞行 POSSIBLE_IN_KFC = false# not seen in KFC summer = Chicken () print (summer.have_feather) PR Int (Summer.move (5, 8)) print (summer.way_of_reproduction) print (summer.way_of_move) #chicken Oriole is the new two class, are inherited from the bird. #bird is the parent class #chicken Oriole is the subclass #chicken Oriole inherit all the properties of bird, you can see the feather and the way of the reproduction print # We define summer is chicken, by inheriting the property that owns the bird # execution, look at the "output: true[5, 8]eggwalk ' #修改一下, convenient for later viewing summer = Chicken () print (' Summer.have_feather: ', summer.have_feather) print (' After move: ', Summer.move (5, 8)) print (' Summer.way_of_ Reproduction is ', summer.way_of_reproduction) print (' Summer.way_of_move is ', summer.way_of_move) ' Output: Summer.have _feather:trueafter move: [5, 8]summer.way_of_reproduction is Eggsummer.way_of_move is Walk ' ' #这里作者讲述了一些关于面向对象和面向过程的说法 #面向对象是符合人类思维的, according to the way of thinking of the class, is the human # process, is the execution of the program and then the next sentence, more machine thinking # Here the object-oriented and process-oriented, it should be that every programmer has his own thinking, like the same workEvery programmer can write a different code. # As for the teacher of C said the object-oriented process of the argument, has completely forgotten the "" to classify things according to attributes, the object (things) into Class (class), there is classclass inside has attributes, is attribute. Object object = Class () Summer = Chicken () Summer.move Reference Chicken Property Moveobject.attribute property of Reference object parent class-subclass subclass inherits all properties of parent class "through inheritance system , we can reduce the repetition and repetition in the program "if we define two classes separately, and do not inherit from the birds, we must enter the bird's attributes into the definition of the chicken and the oriole." The whole process becomes cumbersome, so object-oriented improves the reusable nature of the program I don't think it's tedious, Will enter a lot of content, Python, after all, the more simple and easy to read self does not understand the object created by the class definition, later in-depth "
Python Learning Notes (eight) object-oriented basic concepts