定義一個類
class 類名
class HelloWorld
定義類的構造方法
def init(self)
def __init__(self,name,age):
self.name=name
self.age=age
print("my name is {0} age is {1}".format(name,age));
h=HelloWorld("郭金龍",22)
繼承一個類
class Hi(HelloWorld):
def __init__(self, name):
HelloWorld.__init__(self,name,22)//引用該類的父類的構造方法
def sayHi(self):
print("say my name---{0}".format(self.name))
h=HelloWorld("郭金龍",22)
h1=Hi("郭金龍")
h1.sayHi()