1. 定義類 class MyFirstClass: //構(gòu)造函數(shù) def __init__(self): print("Create MyFirstClass") //定義對象 self.name = "myclass" def setname(self, name): self.name = name def print(self): print(self.name) 2. 類的繼承 class MyNewClass (MyFirstClass): def setage(self, age): self.age = age def print(self): print(self.name) print(self.age)
|
|
來自: 黎可圖書館 > 《Python 學習》