类的经典实例

author:headsen  chen

date: 2018-11-29  17:36:42

class p:
    def __init__(self,na,gen,age,fig):
        self.name = na
        self.gender =gen
        self.age =age
        self.fight =fig

    def grassland(self):
        self.fight = self.fight - 200

    def practice(self):
        self.fight =self.fight +200
    def incest(self):
        self.fight =self.fight - 500
    def detail(self):
        temp = "姓名:%s;性别:%s;年龄:%s;战斗力:%s" %(self.name,self.gender,self.age,self.fight)
        print(temp)

cang = p('苍井空','',18,1000)
dong = p('懂你打算','',22,1800)
bo = p('波尔生生','',26,3000)

cang.incest()
dong.practice()
bo.grassland()

cang.detail()
dong.detail()
bo.detail()
原文地址:https://www.cnblogs.com/kaishirenshi/p/10039798.html