Three major characteristics: 1, Encapsulation: In the class to the data assignment, internal calls to the external user is transparent, which makes the class into a capsule or container, the bread containing the class data and methods 2, inheritance: A class can derive subclasses, the properties defined in the parent class, methods will automatically inherit the class # class People: #经典类class People (object): #新式类def __init__ (self,,age): Self.name = Self.age = Age def eat (self):p rint ('%s ') Eating '%self.name) def work (self):p rint ("%s are work hard"%self.name) class Man (People): # Subclass inherits People parent Def __init__ (self,name,age,sex): #People. __init__ (self, name, age) Super (man, self). __INIT__ (name, age) # New self.sex = Sex def drink (self):p rint ("%s was drinking"%self.sex) class Woman (people):d EF get_brith (self): Print ("%s is get"% self.name) def eat (self):P eople.eat (self) m1 = Man ("Mmmmm", 23, "male") m1.eat () M1.drink () w1 =woman ("Wwwww", $) W1.get_brith () W1.eat () # class people: #经典类class people (object): #新式类def __init__ (self,,age): Self.name = Self.age = Age def eat (self):p rint ('%s was eating '%self.name) def work (self):p rint ("% S is work hard "%self.name) class Man (people): #子类继承People父类def __init__ (Self,naMe,age,sex): #People. __init__ (self, name, age) Super (Mans, Self). __INIT__ (name, age) #新式self. Sex = Sex def drink ( Self):p rint ('%s is drinking '%self.sex) class Woman (people):d EF get_brith (self):p rint ('%s is get '% self.name) def eat (self):P eople.eat (self) m1 = Man ("Mmmmm", 23, "male") M1.eat () M1.drink () w1 =woman ("Wwwww", W1.get_brith () w1.eat () 3, polymorphism: One interface, multiple implementations: interface reuse Syntax: calling functions--> Method Construction Method: Contrary to the constructor, it is executed automatically when the instance is disposed, destroyed, and is usually used to do some finishing work, such as closing a database link or closing some temporary files private methods: Def __eat (): Two kinds of query strategies; Breadth First: Python 3.x Python 2.x's new class depth priority: Python 2.x classic class is a depth-first query strategy
Python Growth notes-Basic (vii) Python object-oriented