- Class: Simply a collection of functions in which you define a number of functions;
- Method: These are actually the functions you define.
- Object: In simple terms, it is a variable that has multiple attributes (or sub-variables).
- In the example below, Class Plus is a class, and the two functions nested within this class are called methods, but __init__ is only used to initialize the class, so it is not a method.
- and Get_result This function is a method.
- C1 and C2 are two instances, but they have a common attribute and template
Example of a class:
1 #!usr/bin/python2 #Coding=utf-83 classPlus:4 #Self is an object with two parameters inside the object self.a,self.b5 def __init__(self,a=0,b=0,c=0,d=0):6SELF.A =a7SELF.B =b8SELF.C =C9SELF.D =DTen defGet_result (self): One returnSELF.A +self.b A defget_sum (self): - returnself.b+SELF.D - the - if __name__=='__main__': -C1 = Plus (7,8)#C1 represents an example -RESULT1 = C1.get_result () + Printresult1 # output results are -C2 = Plus (0,4,5,9)#C2 is also an example +RESULT2 = C2.get_sum () A PrintResult2# Output is the result of
Python (14) class, method, object, instance