1.什么是继承?

  新类不用从头编写

  新类从现有的类继承,就自动拥有了现有类的所有功能

  新类只需要编写现有类缺少的新功能

2.继承的好处

  复用已有代码

  自动拥有了现有类的所有功能

  只需要编写缺少的新功能

3.父类和子类

 #定义一个父类,也称为及基类,超类
class father(object):
def __init__(self,name,gender):
self.name = name
self.gender = gender #定义一个子类,也称为派生类,继承类
class child(father):
def __init__(self,name,gender,score):
#初始化父类,否则继承自father的child将没有name和gender
super(child,self).__init__(name,gender)
self.score = score t = child('Tom','Six','')
print t.name

4.继承的特点

  子类和父类是is关系

class child(father):
pass p = father()
s = child()

p 是一个 father 但不是一个child

s 是一个father 同时也是一个person

最新文章

  1. 关于C#联接数据库是出现'未在本地计算机上注册'错误的解决办法
  2. 突袭HTML5之SVG 2D入门1 - SVG综述////////////////zzzzzzzz
  3. 网络存储技术介绍(2) ( based on zt)
  4. Office 2010启动时出现无法验证此应用程序的许可证的解决
  5. HTML常用的特殊字符格式
  6. JavaScript--匿名函数和闭包(16)
  7. 使用cocos2d-x制作 Texture unpacker
  8. Ubuntu 12.04 安装sougou for linux
  9. Android 自定义View修炼-自定义弹幕效果View
  10. 在SQL Server 实现递归
  11. jQuery设置checkbox全选(区别jQuery版本)
  12. shell编程-1到100的求和与冒泡排序
  13. tomcat 下部署 php
  14. js对象个人理解及记录
  15. Elasticsearch聚合——aggregation
  16. Android Intent 基本使用及对象构成
  17. Twisted 使用多线程
  18. AngularJS学习之旅—AngularJS 模块(十五)
  19. [NOI 2018] 归程
  20. mysql导出表的字段及相关属性

热门文章

  1. IOS-连接
  2. [AngularJS] Angular 1.5 $transclude with named slot
  3. Archlinux 从 AUR 源中安装应用
  4. http://msh.baidu.com/UTWpR6wY4722
  5. django: template - built-in tags
  6. java开发的web下载大数据时的异常处理
  7. ASP.net导出Excel的几种方式
  8. Arcgis - Personal Geodatabase 和 File Geodatabase的区别.
  9. YUI 之getLocation
  10. 在Yii2中使用Pjax导致Yii2内联脚本载入失败的问题