1.python support function + Object oriented
2. Syntax
Class Foo: #创建类
#方法
Def Mail (self,email,message): #self是自带的, must have
Print ("Send")
Return True
#调用
Obj=foo () #创建对象, Object = Class name ()
Obj.mail (' [email protected] ', ' test_message ') #通过对象去执行方法
3. Functional vs. Object-oriented
When some functions have the same parameters, such as user passwords, you can use object-oriented to encapsulate parameter values into objects.
#function TypedefA (AVG1,AVG2,AVG3):Print(AVG1,AVG2,AVG3)defB (avg1,avg2,avg4):Print(AVG1, AVG2, Avg4) A (avg1='test1', avg2='test2', avg3='test3') b (Avg1='test1', avg2='test2', avg4='test4')#Object OrientedclassFoo:defA (SELF,AVG3):Print(SELF.AVG1, SELF.AVG2, AVG3)defB (self,avg4):Print(SELF.AVG1, self.avg2, avg4) obj=Foo () obj.avg1='test1' #the shared variables are encapsulated in the Obj objectObj.avg2='test2'obj.a ('test3')#only non-encapsulated parameters are passedOBJ.B ('test4')
Python Object-oriented