2716811483 发表于 2020-3-28 17:14:20

求助函数嵌套

def fun1():
        x = 3
        def fun2():
                nonlocal x
                x *= x
                return x
        return fun2()
fun1()

为啥我这个什么都不打印,输出就是空白。

zltzlt 发表于 2020-3-28 17:17:13

需要 print()

def fun1():
      x = 3
      def fun2():
                nonlocal x
                x *= x
                return x
      return fun2()
print(fun1())

hrp 发表于 2020-3-28 17:20:12

print(fun1())
页: [1]
查看完整版本: 求助函数嵌套