zoukankan      html  css  js  c++  java
  • 面向对象联系

    #面向对象
    # 类:把一类事物的相同特性和动作整合到一起就是类。类是抽象的
    # 对象:就是基于类而创建的一个具体的事物(具体存在的),也是特征和动作整合一起

    #类:学校
    #类的特征:校名,地址,性质
    #对象(动作,功能):招生,放假

    #用函数实施面向对象编程
    def school(name,addr,type):
    def init(name,addr,type):
    sch = {
    'name':name,
    'addr':addr,
    'type':type,
    'zhao_sheng':zhao_sheng,
    'fang_jia':fang_jia
    }
    return sch
    def zhao_sheng(sch):
    print('%s 正在招生'%sch['name'])

    def fang_jia(sch):
    print('位于%s的%s学校%s已经放假了'%(sch['addr'],sch['type'],sch['name']))
    return init(name,addr,type)

    a = school('杭电','杭州','公立')
    print(a) #{'name': '杭电', 'addr': '杭州', 'type': '公立', 'zhao_sheng': <function school.<locals>.zhao_sheng at 0x0000000002300B70>, 'fang_jia': <function school.<locals>.fang_jia at 0x0000000002300EA0>}

    a['zhao_sheng'](a) #杭电 正在招生

    c = school('苏大','苏州','公立')
    c['fang_jia'](c)#位于苏州的公立学校苏大已经放假了


    #用类class来实施面向对象编程
    class dog:
    def __init__(self,name,type,color):
    self.name = name
    self.type = type
    self.color = color
    def jiao(self):
    print('%s狗在叫' %self.name)

    def chi_shi(self):
    print('%s狗%s在吃屎' %(self.type,self.name))

    def shui_j(self):
    print('%s是%s色' %(self.name,self.color))


    a = dog('豆豆','公','黄色')
    a.jiao() #豆豆狗在叫

    b = dog('臭臭','母','白色')
    b.shui_j() #臭臭是白色色
  • 相关阅读:
    HDU 1847
    HDU 1717
    KMP未优化模板、
    Codeforces Round #340 (Div. 2) B. Chocolate
    HDU 1042 N!
    HDU 1018 Big Number
    HDU 1031 Design T-Shirt
    解决Windows 7删除执行过的 EXE、Bat文件有延迟的问题
    修改Android手机的“虚拟机堆大小”和android:largeHeap来防止APP内存溢出问题
    Android引用百度定位API第三方组件后导致其它.so文件无法正常加载的问题
  • 原文地址:https://www.cnblogs.com/lhqlhq/p/8821348.html
Copyright © 2011-2022 走看看