• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python 类的继承实例详解

Python 类的继承实例详解

作者:lqh 字体:[增加 减小] 来源:互联网

lqh 通过本文主要向大家介绍了python类详解,python开发技术详解,python os模块详解,python正则表达式详解,python 字典详解等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

Python 类的继承详解

Python既然是面向对象的,当然支持类的继承,Python实现类的继承比JavaScript简单。

Parent类:

class Parent: 
 
  parentAttr = 100 
 
  def __init__(self): 
    print("parent Init") 
 
  def parentMethod(self): 
    print("parentMethod") 
   
  def setAttr(self,attr): 
    self.parentAttr = attr 
 
  def getAttr(self): 
    print("ParentAttr:",Parent.parentAttr) 
</div>

Child类

class Child(Parent): 
 
  def __init__(self): 
    print("child init") 
 
  def childMethod(self): 
    print("childMethod") 
</div>

调用

p1 = Parent(); 
p1.parentMethod(); 
 
c1 = Child(); 
c1.childMethod(); 
</div>

输出:

parent Init 
parentMethod 
child init 
childMethod 
Press any key to continue . . . 
</div>

Python支持多继承

class A:    # 定义类 A 
..... 
 
class B:     # 定义类 B 
..... 
 
class C(A, B):  # 继承类 A 和 B 
..... 
</div>

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

</div>

您可能想查找下面的文章:

  • Python中异常重试的解决方案详解
  • 详解python 字符串和日期之间转换 StringAndDate
  • Python中异常重试的解决方案详解
  • 详解python 字符串和日期之间转换 StringAndDate
  • 详解Python中类的定义与使用
  • python获取指定时间差的时间实例详解
  • 详解Python中类的定义与使用
  • python获取指定时间差的时间实例详解
  • Python 类的继承实例详解
  • python 类详解及简单实例

相关文章

  • 利用Python的装饰器解决Bottle框架中用户验证问题
  • python中执行shell命令的几个方法小结
  • Django中实现点击图片链接强制直接下载的方法
  • Python中List.count()方法的使用教程
  • Python time模块详解(常用函数实例讲解,非常好)
  • 十条建议帮你提高Python编程效率
  • 让python json encode datetime类型
  • Python的一些用法分享
  • python字典排序实例详解
  • Python实现图像几何变换

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • python登录pop3邮件服务器接收邮件的方法
    • 编写Python小程序来统计测试脚本的关键字
    • 详解Python中映射类型(字典)操作符的概念和使用
    • tensorflow模型保存、加载之变量重命名实例
    • Python3.2模拟实现webqq登录
    • Python中使用SAX解析xml实例
    • Django自定义插件实现网站登录验证码功能
    • Python利用Nagios增加微信报警通知的功能
    • 打开电脑上的QQ的python代码
    • python 类详解及简单实例

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有