Simple introduction and method invocation of class/function/module in Python+selenium

Source: Internet
Author: User
Tags class definition instance 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
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.