• Python 类 类的封装,继承 ,多继承


    __author__ = '12711'
    #-*- coding:utf-8 -*-
    # class Animal(object):
    # name='xxx'
    # def __init__(self,name,age):
    # self.name=name
    # self.age=age
    #
    # def eat(self):
    # print("%s开始吃东西了"%(self.name))
    #
    # def seelp(self):
    # print("%s开始睡觉了"%(self.name))
    #
    # t=Animal('小花',22)
    # print(Animal.name)
    # t.seelp()
    # t.eat()


    #类的封装
    # class Animal(object):
    # def __init__(self,name,age):
    # self.__name=name
    # self.age=age
    #
    # def __eat(self):
    # print("%s开始吃东西了"%(self.__name))
    #
    # def seelp(self):
    # print("%s开始睡觉了"%(self.__name))
    # t=Animal('xiaohua',22)
    # t.eat()
    # t.seelp()

    # class A:
    # def fa(self):
    # print('from A')
    # def test(self):
    # self.fa()
    #
    # class B(A):
    # def fa(self):
    # print('from B')
    #
    # b=B()
    # b.test()

    # class A:
    # def __fa(self):
    # print('from A')
    # def test(self):
    # self.__fa()
    #
    # class B(A):
    # def __fa(self):
    # print('from B')
    #
    # b=B()
    # b.test()

    #类的继承

    # class Animal(object):
    # def __init__(self,name,age):
    # self.name=name
    # self.age=age
    #
    # def Age(self):
    # print("%s已经%d岁了"%(self.name,self.age))
    #
    # def eat(self):
    # print("%s开始吃东西了"%(self.name))
    #
    # def seelp(self):
    # print("%s开始睡觉了"%(self.name))
    #
    # class Dog(Animal):
    # def __init__(self,name,age,color):
    # super(Dog,self).__init__(name,age)
    # self.color=color
    #
    # def voice(self):
    # print("%s汪汪汪的叫起来。。"%(self.name))
    #
    #
    # class Cat(Animal):
    # def __init__(self,name ,age,color):
    # super(Cat,self).__init__(name,age)
    #
    #
    # def voice(self):
    # print("%s喵喵喵的叫起来了。。"%(self.name))
    #
    #
    #
    # t1=Dog("小白",3,"白色")
    # t2=Cat("小花",2,"黑白斑点")
    # t1.seelp()
    # t1.eat()
    # t1.Age()
    # t1.voice()
    # t2.seelp()
    # t2.eat()
    # t2.Age()
    # t2.voice()

    #类的多继承
    class Animal(object):
    def __init__(self,name,age):
    self.name=name
    self.age=age

    def Age(self):
    print("%s已经%d岁了"%(self.name,self.age))

    def eat(self):
    print("%s开始吃东西了"%(self.name))

    def seelp(self):
    print("%s开始睡觉了"%(self.name))

    class Love(object):
    def frand(self,obj):
    print("%s和%s变成了朋友"%(self.name,obj.name))

    class Dog(Animal,Love):
    def __init__(self,name,age,color):
    super(Dog,self).__init__(name,age)
    self.color=color

    def voice(self):
    print("%s汪汪汪的叫起来。。"%(self.name))


    class Cat(Animal):
    def __init__(self,name ,age,color):
    super(Cat,self).__init__(name,age)


    def voice(self):
    print("%s喵喵喵的叫起来了。。"%(self.name))


    t1=Dog("小白",3,"白色")
    t2=Cat("小花",2,"黑白相间")
    t1.frand(t2)
  • 相关阅读:
    开发用于异构环境的可生存云多机器人框架
    RVIZ实现模拟控制小车
    airsim 无法打开包括文件corecrt.h
    RoboWare Studio 安装
    Rosserial实现Windows-ROS交互操作
    nuix .pl文件运行
    OSError:[Errno 13] Permission denied:'my_library' 问题解决方法
    ros 运行rviz时出现 QXcbConnection: XCB error: 148 错误 解决方法
    在linux下一般用scp这个命令来通过ssh传输文件
    unix下命令窗分屏工具
  • 原文地址:https://www.cnblogs.com/hjdshizhidong/p/9812931.html
Copyright © 2020-2023  润新知