day07 年 月 日

class Date:
    def __init__(self, year, month, date):
        self.year = year
        self.month = month
        self.date = date

    @classmethod  # 类方法,不用创建实例即可调用
    def create(cls, dstr):  # cls表示类本身, class
        y, m, d = map(int, dstr.split('-'))  # map(int, ['2000', '5', '4'])
        dt = cls(y, m, d)
        return dt

    @staticmethod
    def is_date_valid(dstr):
        y, m, d = map(int, dstr.split('-'))
        return 1 <= d <= 31 and 1 <= m <=12 and y < 4000

if __name__ == '__main__':
    bith_date = Date(1995, 12, 3)
    print(Date.is_date_valid('2000-5-4'))
    day = Date.create('2000-5-4')
    print(day)#######

#####################################

lass BearToy:
    def __init__(self, nm, color, size):
        self.name = nm
        self.color = color  # 绑定属性到实例
        self.size = size

    def sing(self):
        print('lalala...')

    def speak(self):
        print('My name is %s' % self.name)

class NewBear(BearToy):
    def __init__(self, nm, color, size, date):
        # BearToy.__init__(self, nm, color, size)
        super(NewBear, self).__init__(nm, color, size)
        self.date = date

    def run(self):
        print('running...')

if __name__ == '__main__':
    b1 = NewBear('venie', 'Brown', 'Small', '2018-07-20')
    b1.sing()
    b1.run()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值