python的super关键字使用示例,pythonsuper关键字,super在单继承中使用
python的super关键字使用示例,pythonsuper关键字,super在单继承中使用
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
相关内容
- os.rename()导致WindowsError: [Error 32]问题的解决,,刚接触
- Python实现通用的unix/linux守护进程,python守护进程,下面
- python 3.x创建linux/unix守护进程类,python守护进程,如下是
- python使用socket监听客户端发送文本内容,pythonsocket,下面
- python 控制语句 else,pythonelse,python中的else
- 两种python 判断网页编码的方法,python判断网页编码,这
- python字符串方法总结,python字符串总结,python的字符串模
- python 使用datetime模块timedelta实现日期时间相加,dateti
- python时间日期模块使用总结,python模块,python中关于时间
- python string to datetime datetime to string,pythondatetime,python日
评论关闭