你的分享就是我们的动力 ---﹥

python学习笔记07:自定义类型

时间:2016-12-16 19:11来源:www.chengxuyuans.com 点击:
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())

运行结果:

转载注明地址:http://www.chengxuyuans.com/Python/105682.html

推荐文章