Python继承
继承实例:
父类和子类的关系:
继承树:
没有父类就继承object类,
不要忘记调用super().__init__来初始化父类
代码:
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