[Python] basic grammar exercises on the 10th day job

"""
1, class attributes define how? Examples of how attribute definition? What properties suitable for defining a class attribute bits, when what attribute is defined as an instance attribute (short answer)
    Class attribute definitions: directly inside the class definition of variables, called the class attributes
    Examples of attribute definitions: Object attribute name = attribute value
    
    Class attribute: These things all objects have this attribute, attribute values ​​are the same, for class attribute is defined as
    Examples of attributes: These things all objects have this property, but the property value is not the same, for instance property is defined as
2. What are examples of methods of self representatives? (Short answer)
    self represents the object itself (himself), which object calls this method represents that object.   
3, class __init__ method calls at what time? (Short answer)
    When creating an object will automatically call
4, a package student class,
- attributes: name, age, gender, achievement in English, math, language scores,
- Method One: Calculate the total score, Method Two: Calculate the average three subjects, Method three: Print student's personal information.
5, a test class package,
- Properties: Example No. url address request with the results of actual parameter request method Expected Results

"" " 
# Problem 4 
class Students.:
     '' ' Student class ' '' 
    DEF  the __init__ (Self, name, Age, Gender, Dictionary Dictionary English, Math, chinese):
         # Example student class attribute defines 
        the self.name = name
        self.age = age
        self.gender = gender
        self.english = english
        self.math = math
        self.chinese = chinese
     # define student class instance method: implement certain functions 
    # overall score 
    DEF sum_score (Self):
         # overall score 
        RES = self.english self.math + + self.chinese
         return RES

    def avg_score(self):
        """计算平均分"""
        res = (self.english + self.math + self.chinese) / 3
        return res

    DEF desc_info (Self):
         "" " print information " "" 
        Print ( ' trainee name: {}, Age: {}, Sex: {} ' .format (self.name, self.age, self.gender))


# Create a Student object, call out the calculation method 
hc = Students (name = " hc " ,
             age=18,
             gender="",
             english=100,
             math=100,
             chinese=100,
             )

# Method One: Calculate the total score 
Print (hc.sum_score ())
 # Method Two: Calculate Average 
Print (hc.avg_score ())
 # Method three: Print student's personal information 
Print (hc.desc_info ())

# Fifth title

class Cases:
    """用例类"""

    def __init__(self, case_id, url, data, method, excepted, actual):
        self.case_id = case_id
        self.url = url
        self.data = data
        self.method = method
        self.excepted = excepted
        self.actual = actual


# Class attributes: class and instance objects can call 
# instance properties: as long as the instance of an object to be able to call

 

Guess you like

Origin www.cnblogs.com/python-test001/p/12395594.html