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

    1、原始代码

     1 def school(name,addr,type):
     2     def kao_shi(school):   #功能性用函数
     3         print('%s正在考试'%school['name'])
     4 
     5     def zhao_sheng(school):
     6         print('%s招生的地址是:%s'%(school['name'],school['addr']))
     7     school01={
     8         'name':name,
     9         'addr':addr,
    10         'type':type,
    11         'kao_shi':kao_shi,#建立与函数def kao_shi的联系
    12         'zhao_sheng':zhao_sheng   #建立与函数def zhao_sheng的联系
    13 
    14     }    #描述性的内容用字典
    15     return school01
    16 
    17 s1=school('hncj','xinchengqu','公立')
    18 s1['zhao_sheng'](s1)
    19 s1['kao_shi'](s1)
    20 
    21 >>>
    22 hncj招生的地址是:xinchengqu
    23 hncj正在考试

     2、二次改进

     1 def school(name,addr,type):
     2     def kao_shi(school):   #功能性用函数
     3         print('%s正在考试'%school['name'])
     4 
     5     def zhao_sheng(school):
     6         print('%s招生的地址是:%s'%(school['name'],school['addr']))
     7     def init(name,addr,type):
     8         school01={
     9             'name':name,
    10             'addr':addr,
    11             'type':type,
    12             'kao_shi':kao_shi,
    13             'zhao_sheng':zhao_sheng
    14 
    15         }    #描述性的内容用字典
    16         return school01
    17     return init(name,addr,type)
    18 
    19 s1=school('hncj','xinchengqu','公立')
    20 s1['zhao_sheng'](s1)
    21 s1['kao_shi'](s1)
    22 
    23 >>>
    24 hncj招生的地址是:xinchengqu
    25 hncj正在考试
  • 相关阅读:
    vue 中使用阿里iconfont彩色图标
    团队作业九
    团队作业八
    团队作业七
    第二篇
    第三篇
    第一篇
    beta冲刺计划安排
    团队作业六
    团队作业五
  • 原文地址:https://www.cnblogs.com/forhowcar/p/12257925.html
Copyright © 2011-2022 走看看