class Student():
# self 自己
# 方法名前后带两个下划线叫做魔法方法,pyton自带的具有特殊功能的方法
def __init__(self, name):
self.name = name
self.hp = 100
self.speed = 30
self.voice = 0.5
self.IQ = 95
def get_hp(self):
print(self.hp)
def xiugai(self, new_hp):
self.hp = self.hp + new_hp
if self.hp >= 180:
print('您已开挂,请2099年再次登录')
self.hp = self.hp - new_hp
def run(self):
print("逃跑")
def study(self):
print('学习中')
self.IQ = self.IQ + 5
def play(self):
print('玩耍中')
self.hp = self.hp - 5
def __str__(self):
return "我是%s" % self.name
class Teacher():
def sing(self):
print("sing")
# 万物皆对象\
# 继承
class child(Student, Teacher):
def __init__(self, name):
self.name = name
self.hp = 100
self.speed = 30
self.voice = 0.5
self.IQ = 95
def cry(self):
print("cry cry")
self.hp = self.hp - 10
# 新建学生对象
S1 = Student("Sam")
print(S1)
S2 = Student("佩奇")
print(S2)
c1 = child("乔治")
print(c1)
c1.cry()
c1.study()
c1.play()
succi -类与对象2
最新推荐文章于 2020-07-18 14:53:10 发布