1 #Coding=utf-82 3 classClassA (object):4string1 ="this is a string. "5 6 defInstancefunc (self):7 Print('This is an instance method. ')8 Print('the value of the Selef is:', self)9 Ten @classmethod One defClassfunc (CLS): A Print('This is a class method. ') - Print('the value of the CLS is:', CLS) - the @staticmethod - defStaticfun (): - Print('This is a static method. ') - + -Test = ClassA ()#Initializes an Classsa object, test is an instance object of class ClassA +Test.instancefunc ()#Object Invocation instance method A atTest.staticfun ()#object calls a static method - -Test.classfunc ()#object Call class method - - Print(TEST.STRING1)#object calls a class variable - inClassa.instancefunc (Test)#class calls an instance method, which takes parameters, here the test is an object parameter -Classa.instancefunc (ClassA)#class calls an instance method, which takes parameters, where the ClassA is a class parameter toClassa.staticfun ()#class calls a static method +Classa.classfunc ()#class Call class method
1 #Coding=utf-82 3 classClassA (object):4string1 ="this is a string. "5 6 defInstancefunc (self):7 Print('This is an instance method. ')8 Print('the value of the Selef is:', self)9 Ten @classmethod One defClassfunc (CLS): A Print('This is a class method. ') - Print('the value of the CLS is:', CLS) - the @staticmethod - defStaticfun (): - Print('This is a static method. ') - + -Test = ClassA ()#Initializes an Classsa object, test is an instance object of class ClassA +Test.instancefunc ()#Object Invocation instance method A atTest.staticfun ()#object calls a static method - -Test.classfunc ()#object Call class method - - Print(TEST.STRING1)#object calls a class variable - inClassa.instancefunc (Test)#class calls an instance method, which takes parameters, here the test is an object parameter -Classa.instancefunc (ClassA)#class calls an instance method, which takes parameters, where the ClassA is a class parameter toClassa.staticfun ()#class calls a static method +Classa.classfunc ()#class Call class method
Note:
The main points are as follows:
1. The class definition, which begins with class, indicates that this is a class, enclosed in parentheses, that represents the parent class of the class, which involves inheritance, and the default object is the parent class of all classes.
In Python, there are three main types of classes defined in parentheses: 1. A specific parent class, 2. Object 3. Blank
2. Definition of a function or method, Def begins with a definition of a function, including, instance methods, class methods, static methods, and notice that the class method and static method definitions have an @ tag at the time.
3. The object invokes methods and uses of the class invocation method.
The following Baidu search example, imitate the above with the method of invoking the class to write this script, note that this is the current Baidusearch this class itself :
Simple introduction and method invocation of class/function/module in Python+selenium