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正在考试
  • 相关阅读:
    Maven介绍及安装与配置
    Xshell使用技巧总结
    UML类图
    vim使用案例
    Linux常用命令3(压缩和解压缩总结)
    Linux常用命令2(远程文件下载+查看文件内容)
    Linux常用命令1
    JOptionPane类提示框常用方法总结
    HTTP基础知识3
    HTTP基础知识2
  • 原文地址:https://www.cnblogs.com/forhowcar/p/12257925.html
Copyright © 2011-2022 走看看