用字典储存函数的引用

# 最近学习mini_web服务器 发现用字典储存函数的引用非常方便

 

# 字典可以储存一个函数的返回值
def index():
  return "content"


dic = {"index": index()}

print(dic["index"]) # 返回了函数的返回值 “content”

 

 

# 后续调用

file_name = "index"

def application():

  return dict["index"]     # 返回了index函数的返回值“content”

  

 

posted @ 2018-03-14 11:15  Levy_Y  阅读(162)  评论(0)    收藏  举报