封装 实例
1 class person: 2 def __init__(self,name,age,weight): 3 self.Name = name 4 self.Age = age 5 self.Weight = weight 6 def chi(self): 7 self.Weight+=2 8 def exercise(self): 9 self.Weight-=1 10 11 o1 = person('小米',20,200) 12 w = o1.Weight 13 print(w) 14 o1.chi() 15 print(o1.Weight) 16 o1.chi() 17 o1.chi() 18 print(o1.Weight) 19 o1.exercise() 20 o1.exercise() 21 o1.exercise() 22 23 print(o1.Weight)