We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
python中什么是继承:
新类不必从头编写 新类从现有的类继承,就自动拥有了现有类的所有功能 新类只需要编写现有类缺少的新功能
继承的好处:
复用已有代码 自动拥有了现有类的所有功能 只需要编写缺少的新功能
继承的特点:
子类和父类是is关系
python继承的特点:
总是从某个类继承
1 class Person(object): 2 def __init__(self, name, gender): 3 self.name = name 4 self.gender = gender 5 class Teacher(Person): 6 def __init__(self, name, gender, course): 7 super(Teacher, self).__init__(name, gender) 8 self.course = course 9 10 t = Teacher('Alice', 'Female', 'English') 11 print t.name 12 print t.course
调用父类的方法: super(object, self).sub_perform_create(serializer) 3.当继承的有多个父类而且父类有同名方法时,默认调用第一个父类的方法
4.getattr()、setattr()以及hasattr()
if hasattr(obj,'attr') ---判断某个类有没有什么属性 getattr(obj,'attr') ---获取某个类的什么属性 setattr(obj,'attr',a) --将某个类某属性的直设为a
The text was updated successfully, but these errors were encountered:
No branches or pull requests
python中什么是继承:
继承的好处:
继承的特点:
python继承的特点:
复制代码
调用父类的方法:
super(object, self).sub_perform_create(serializer)
3.当继承的有多个父类而且父类有同名方法时,默认调用第一个父类的方法
4.getattr()、setattr()以及hasattr()
The text was updated successfully, but these errors were encountered: