面向物件-面向物件的可拓展性
阿新 • • 發佈:2018-12-31
class Chinese: country = 'China' def __init__(self, name, sex, age): self.Name = name self.Sex = sex self.Age = age def eat(self): print('%s is eatting' % self.Name) def learn(self): print("%s is learning, %s is %s years old" % (self.Name, self.Name, self.Age)) stu1= Chinese('egon', 'male', 18) stu2 = Chinese('alex', 'male', 28) stu3 = Chinese('wusi', 'male', 38) print(stu1) # ---><__main__.Chinese object at 0x11039b320> print(stu1.eat()) # ---> egon is eatting;物件.方法 print(stu2.learn()) # ---> alex is learning, alex is 28 years old