python學習筆記07:自定義類型

class person:
    def __init__(self,name,age,weight):
        self.name = name
        self.age = age
        self.weight = weight
    def SayHi(self):
        print('Hi %s' % (self.name))
    def ToString(self):
        return 'name: %s \nage: %d \nweight: %d \n' % (self.name, self.age, self.weight)

if __name__ == '__main__':
    alex = person('alex',30,70)
    alex.SayHi()
    print(alex.ToString())

運行結果:
spa

相關文章
相關標籤/搜索