Object oriented
Only object-oriented programming can be used in the java,c# language, and in Python, when some functions have the same parameters, object-oriented programming is used to encapsulate the parameters once to the object, and then the objects can be
classF1:def __init__(SELF,A1,B1,C1): self.a1=A1 self.a2=B1 self.a3=C1defSelect (self,sql):Print(Self.a1,self.a2,self.a3,sql)defAdd (self,sql):Print(SQL)#__init__ construction method for automatic execution of classes when instantiatedobj = F1 ('1','2','3') Obj.host='abc.com'Obj.username='Alex'obj.pwd='123'#use object-oriented when some functions have the same parametersObj.select ('SELECT * from A') Obj.add ('CREATE table from A')>>>1 2 3 SELECT * fromA>>>create table fromA
1 classC1:2 def __init__(self,name,obj):3Self.name =name4Self.obj =obj5 6 classC2:7 def __init__(self,name,age):8Self.name =name9Self.age = AgeTen defShow (self): One Print(Self.name) A -C2_obj = C2 ('BB', 18) - #passing c2_obj as a parameter to obj, c1_obj.obj=c2_obj c2_obj.show = C1_obj.obj.show () theC1_obj = C1 ('AA', C2_obj) - c1_obj.obj.show () ->>>bbInherited
1 classF1:#parent class, base class2 defShow (self):3 Print('Show')4 deffoo (self):5 Print(Self.name)6 7 classF2 (F1):#child class, derived class8 def __init__(self,name):9Self.name =nameTen defBar (self): One Print('Bar') A defShow (self): - Print('F2.show') - #inheritance is equivalent to putting the F1 method into F2, theobj = F2 ('Alex') - Obj.foo () - #two classes have the same method, their own methods have high precedence - obj.show () +>>>Alex ->>>f2.show
1 classF1 ():2 defC1 (self):3 Print('C1')4 classF2 (F1):5 defC2 (self):6 Print('C2')7 classf3 (F2):8 defC3 (self):9 Print('C3')Ten One classf5 (): A defC2 (self): - Print('c5') - classf4 (F3,F5): the defC4 (self): - Print('C4') - #when a subclass has two classes, it takes precedence from the left branch, and the left branch finds the head and then looks to the right. -obj =f4 () +OBJ.C2 ()
>>>c2
day6-python-Object-oriented