摘要: 1、使用lambda表达式代替局部函数 def get_math_func(type): result = 1 # 该函数返回的是lambda表达式 if type == 'square': return lambda n: n * n elif type == 'cube': return lam 阅读全文
posted @ 2020-05-06 21:31 蓝小六 阅读(88) 评论(0) 推荐(0) 编辑
摘要: 1、局部函数的使用,可以用于测试自动化编写公共方法,根据传入的type,执行不同的函数体 # 定义一个函数,包含局部函数 def get_mach_func(type, nn): # 定义局部函数1:计算平方 def square(n): return n * n # 定义局部函数2:计算立方 de 阅读全文
posted @ 2020-05-06 19:51 蓝小六 阅读(83) 评论(0) 推荐(0) 编辑