码迷,mamicode.com
首页 > 其他好文 > 详细

面向对象

时间:2020-02-04 00:30:39      阅读:65      评论:0      收藏:0      [点我收藏+]

标签:turn   cheng   内容   ret   init   描述   int   二次   type   

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正在考试

 

面向对象

标签:turn   cheng   内容   ret   init   描述   int   二次   type   

原文地址:https://www.cnblogs.com/forhowcar/p/12257925.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!