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

Python基类函数的重载与调用实例分析

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

shichen2014 通过本文主要向大家介绍了python 基类,派生类调用基类函数,调用基类函数,虚基类的构造函数,基类构造函数等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了Python基类函数的重载与调用方法。分享给大家供大家参考。具体分析如下:

刚接触Python语言的时间不长,对于这个语言的很多特性并不是很了解,有很多用法都是还不知道。今天想着写一个Python面向对象编程时的继承中的函数调用。分享出来,一起进步。

因为之前接触过Java和C++,所有对于面向对象的思想也早已经很熟析的了。这里也不再对面向对象是什么进行赘述了。我们直接上代码吧!看看对于继承和基类函数的调用在Python中是如何调用的~

首先,是基类文件base.py
Created on Dec 18, 2014

@author: raul
'''

class animal(object):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        '''
        print 'animal init'
       
    def say(self):
        print 'animal say'</div>

然后,是子类文件child.py
Created on Dec 18, 2014

@author: raul
'''
from inheritance.base import animal

class cat(animal):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        '''
#         animal.__init__()
        animal.__init__(self)
        print 'cat init'
       
    def say(self):
        animal.say(self)
        print 'cat say'

if __name__ == '__main__':
    c = cat()
    c.say()</div>

运行后,就可以看到输出,如下:

animal init
cat init
animal say
cat say

这就说明,我们的继承和函数的调用都已经OK了

此例子比较简单,不过基本上也讲明白了Python基类函数的重载与调用,希望学习的同学可以举一反三。

希望本文所述对大家的Python程序设计有所帮助。

</div>

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

  • python抽象基类用法实例分析
  • Python基类函数的重载与调用实例分析
  • Python基类函数的重载与调用实例分析

相关文章

  • python不带重复的全排列代码
  • Python自动发邮件脚本
  • python制作花瓣网美女图片爬虫
  • Python学习笔记整理3之输入输出、python eval函数
  • 浅谈function(函数)中的动态参数
  • 详解Python网络爬虫功能的基本写法
  • 简单谈谈python中的多进程
  • Python的print用法示例
  • python进阶教程之函数对象(函数也是对象)
  • Python 出现错误TypeError: ‘NoneType’ object is not iterable解决办法

文章分类

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

最近更新的内容

    • python类和继承用法实例
    • Python使用urllib2获取网络资源实例讲解
    • Python的lambda匿名函数的简单介绍
    • Linux下使用python调用top命令获得CPU利用率
    • python判断图片宽度和高度后删除图片的方法
    • 用Python抢过年的火车票附源码
    • Python中 Lambda表达式全面解析
    • 在Python程序中操作文件之flush()方法的使用教程
    • Pyhton中防止SQL注入的方法
    • python基于xml parse实现解析cdatasection数据

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

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