def line_conf(a, b):

    i = a * b
    def line(x):
        i = i + x
        return i * x + b
    return line
 
line1 = line_conf(4, 5)
print line1(5)
 
在python2.x中报UnboundLocalError错误,原因应该是变量i是函数line_conf()的局部变量,函数调用结束之后也就清除了这个变量,而line1()中需要依赖变量i,才会报这个错误

相关文章:

  • 2021-06-20
  • 2021-07-06
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-26
  • 2022-01-14
  • 2021-05-21
  • 2021-10-25
  • 2021-10-05
  • 2021-08-30
  • 2021-12-06
相关资源
相似解决方案