succi -类与对象2

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()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值