zoukankan      html  css  js  c++  java
  • 继承

    # 单继承
    class GrandP():
        print('GrandP')
    class Father(GrandP):
        print('Father')
    class Son(Father):
        print('Son')
    Son()
    #结果
    GrandP
    Father
    Son
    
    # 多继承
    class Father1():
        print('Father1')
    class Father2():
        print('Father2')
    class Son(Father1,Father2):
        print('Son')
    Son()
    #结果
    Father1
    Father2
    Son
    
    # 派生类
    class Animal():
        def __init__(self,data):
            self.name = data['name']
            self.age = data['age']
            self.sex = data['sex']
        def walk(self):
            print(self.name)
    class dog(Animal):
        def bite(self):
            print('')
    data={
        'name': '小明',
        'age': 21,
        'sex': 'male'
    }
    dog(data).walk()
    #结果
    小明
    
    #组合
    class Mobile():
        def __init__(self, color):
            self.color = color
            
        def call(self):
            print(self.color+'手机打电话')
            
    class People():
        def __init__(self, name, mobile):
            self.name = name
            self.mobile = mobile
            
    mobile = Mobile('红色')
    people = People('小明', mobile)
    print(people.name)
    people.mobile.call()
    #结果
    小明
    红色手机打电话
  • 相关阅读:
    react之redux的使用笔记
    react之jsx的使用
    react之第一个组件的定义及使用
    npm
    webpack热加载
    react使用笔记及生命周期
    移动开发的常见问题
    javascript常用的方法
    cordova local notification plugin
    jqmobi 转换语言
  • 原文地址:https://www.cnblogs.com/daicw/p/12095099.html
Copyright © 2011-2022 走看看