python面向对象

#_*_ coding:utf-8 _*_
class Dog:
    color='yellow'
    def __init__(self,name,age,height):
        self.name = name
        self._age = age
        self.__height = height
    def get__height(self):
        return self.__height

    @classmethod
    def get_color(cls):
        return cls.color

    @property
    def get_age(self):
        return self._age

    def self_introduction(self):
        print 'My name is %s \nI am %s years old\n'%(self.name,self._age)

class GoodDog(Dog):
    def __init__(self,name,age,height,weight):
        Dog.__init__(self,name,age,height)
        #super(GoodDog,self).__init__(name,age,height)
        self.weight = weight
    def self_introduction(self):
        print'My name is %s\nMy weight is %s'%(self.name,self.weight)

def introduce(duixian):
    if isinstance(duixian,Dog):
        duixian.self_introduction()


'''属性
xiaohua=Dog('xiaohuahua',4,20)
print(dir(xiaohua))
print(type(xiaohua))
print(xiaohua.__dict__)
print(xiaohua.__dict__['age'])
print(xiaohua.color)
print(Dog.color)
print(xiaohua.name)
print(xiaohua.get__height)
print(xiaohua._Dog__height)'''

'''方法
xiaohuang=Dog('xiaohuanghuang',5,23)
print(Dog.get_color())
print(xiaohuang.get_age)
xiaohuang.self_introduction()'''

'''继承
xiaobai=GoodDog('xiaobaibai',2,16,33)
print isinstance(xiaobai,Dog)'''

'''多态
xiaoduo=Dog('xiaoduoduo',7,29)
xiaotai=GoodDog('xiaotaitai',12,38,49)
introduce(xiaoduo)
introduce(xiaotai)'''
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值