python继承

Python继承

继承实例:
python继承

父类和子类的关系:
python继承

继承树:
python继承

没有父类就继承object类,
不要忘记调用super().__init__来初始化父类
python继承

代码:

class Person(object):
    def __init__(self, name, gender):
        self.name = name;
        self.gender = gender;

class Student(Person):
        def __init__(self, name, gender ,score):
            super(Student, self).__init__(name, gender);
            self.score = score;

        def whoAmI(self):
            return 'I am a Student, my name is %s' % self.name;

s = Student('lqc', 'female', 99);
print s.whoAmI();            

print type(123);    # <type 'int'>
print type(s);    #<class '__main__.Student'>            

dir(123) # 获取整型变量int的所有属性

复习了一遍~~睡觉(~ o ~)~zZ

上一篇:golang gui library 库


下一篇:【math】梯度下降法(梯度下降法,牛顿法,高斯牛顿法,Levenberg-Marquardt算法)