python2.x 3.x的super关键字使用示例
来源:互联网 发布:php分割字符串 编辑:程序博客网 时间:2024/05/22 04:54
super在单继承中使用的例子:
class Foo(): def __init__(self, frob, frotz) self.frobnicate = frob self.frotz = frotzclass Bar(Foo): def __init__(self, frob, frizzle) super().__init__(frob, 34) self.frazzle = frizzle
此例子适合python 3.x,更多请参考super
如果要在python2.x下使用则需要稍作调整,如下代码示例:
class Foo(object): def __init__(self, frob, frotz): self.frobnicate = frob self.frotz = frotz class Bar(Foo): def __init__(self, frob, frizzle): super(Bar,self).__init__(frob,34) self.frazzle = frizzle new = Bar("hello","world") print new.frobnicate print new.frazzle print new.frotz
0 0
- python2.x 3.x的super关键字使用示例
- Python2.x还是3.x?
- Windows 上同时使用Python2.x 与 3.x
- Python 面向对象 —— super 的使用(Python 2.x vs Python 3.x)
- fcgi.py 从python2.x到3.x的移植
- python2.x与3.x除法的区别
- python2.x与3.x的主要区别笔记
- python2.x与3.x版本print的不同
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- 关于生成内部测试包二维码异地测试
- 去首尾空格
- MVC框架模式(一)
- tilda开机启动不透明
- 如何解决使用ARC后出现的PerformSelector may cause a leak because its selector is unknown
- python2.x 3.x的super关键字使用示例
- 如何解决使用ARC后出现的PerformSelector may cause a leak because its selector is unknown
- Mysql 实现按字段排名(实现oracle的rowNum)
- TCP通信的实现
- 静态成员应用
- Installation error: INSTALL_FAILED_UID_CHANGED解决方案
- android 在开发WebView时,去掉网页的标题并设置成自定义的标题
- 有史以来最困难的题
- web.xml加载顺序