发布于 2017-06-09 05:18:07 | 119 次阅读 | 评论: 0 | 来源: 网友投递
这里有新鲜出炉的Python3 Cookbook中文版,程序狗速度看过来!
Python编程语言
Python 是一种面向对象、解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年。Python语法简洁而清晰,具有丰富和强大的类库。它常被昵称为胶水语言,它能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起。
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)
Child类
class Child(Parent):
def __init__(self):
print("child init")
def childMethod(self):
print("childMethod")
调用
p1 = Parent();
p1.parentMethod();
c1 = Child();
c1.childMethod();
输出:
parent Init
parentMethod
child init
childMethod
Press any key to continue . . .
Python支持多继承
class A: # 定义类 A
.....
class B: # 定义类 B
.....
class C(A, B): # 继承类 A 和 B
.....
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!