建筑结构荷载规范

hHH

 

 1 #!/usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 def outer(func):
 4     def inner():
 5         print("我是内层函数!")
 6     return inner
 7 def foo():
 8     print("我是原始函数!")
 9 # outer(foo)
10 
11 #这里定义了两个函数foo和outer,
12 #outer(foo)表示将foo函数体这个整体传递给outer函数作为参数,并执行outer函数
13 
14 # outer(foo())
15 #outer(foo())表示将foo函数执行后的返回值当做参数传递给outer函数并执行outer函数,
16 #由于foo函数没有指定返回值,实际上它传递给了outer函数一个None。
17 outer(11)
18 #在outer函数内部,返回了一个inner,它是在outer函数内部定义的一个函数,
19 # 注意,由于inner后面没有加括号,所以返回的是inner的函数体,实际上也就是inner这个名字,一个简单的引用而已。
20 # 那么,如果outer函数返回的是inner()呢?现在你应该已经很清楚了,它会先执行inner函数的内容,然后返回个None给outer,outer再把这个None返回给调用它的对象。
View Code

 


HH

posted on 2017-04-20 16:47  肖志威  阅读(92)  评论(0)    收藏  举报

导航