python functions, classes, methods (Mushishi "selenium3 automated testing combat - based on the Python language Notes 4")

1. Function

 

# Defined function: 
DEF the Add (A =. 1, B = 2):   # A =. 1, B = 2 for the default parameters, calculated according to the default parameters does not have a value 
    return A + B 

# calling function: 
C1 = the Add () 
C2 the Add = (. 3,. 5 )
 Print (C1)
 Print (C2)

 

 

2. classes and methods

  • Classes and methods
    # Define a class 
    class Myclass (Object):
         # class defines methods described below, when the difference function, the first argument must be declared, usually with self, self need not be provided in the call value 
        DEF say_hello (self, name):
             return  " Hello, " + name 
    
    # calling class 
    MC = Myclass ()
     Print (mc.say_hello ( " Kite " ))
  • Initialization method
    # Declare when creating a class initializer __ the __init () 
    
    class A:
         # initialization statement 
        DEF  the __init__ (Self, A, B): 
            self.a = int (A) 
            self.b, = int (B) 
    
        # custom methods 
        DEF the Add (Self):
             return self.a + self.b, 
    
    # requires initialization parameters passed when calling class 
    COUNT A = (. 4,. 5 )
     Print (count.add ())
  • inherit
    # Class A Class B inherits 
    class B (A):
         DEF Sub (Self, A, B):
             return A - B
     Print (B (2,. 3) .add ())   # 2+. 3. 5 =

     

 

Guess you like

Origin www.cnblogs.com/kite123/p/11418384.html