python: 多态与虚函数;,,通过python的a
python: 多态与虚函数;,,通过python的a
通过python的abc模块能够实现虚函数;
首先在开头from abc import ABCMeta, abstractmethod
例子 :
#!/usr/bin/python#coding=utf-8from abc import ABCMeta, abstractmethodclass Base(): __metaclass__=ABCMeta #必须先声明 def __init__(self): pass @abstractmethod #虚函数 def get(self): print ‘base get‘ passclass Derivel(Base): def get(self): print "Derivel get"class Derivel2(Base): def get(self): print "Derivel2 get"A = Derivel()B = Derivel2()A.get()B.get()
python: 多态与虚函数;
相关内容
- /和//的区别(python),,/ 除得到的是浮点数
- python:python之禅,,最近在学python
- python 获取网站IP以及服务器,,写了一个识别网站的i
- Python rsplit() 方法,,描述Python r
- python模块之os_sys_动态导入_包,,#!/usr/bin
- [python学习篇][廖雪峰][1]高级特性--创建生成器 方法1
- python 实现下标循环,,Python内置的e
- Python中,关于@property装饰器,,1.为什么使用@pr
- 火币网现货API[Python3版],,火币 期货 现货 A
- 用Python将绝对URL替换成相对URL的代码,,下面的内容内容
评论关闭