Call a function defined in another function

前端 未结 4 1989
梦谈多话
梦谈多话 2020-11-28 14:44

Can I call a function nested inside another function from the global scope in python3.2?

def func1():
    def func2():
        print(\"Hello\")
        retur         


        
4条回答
  •  粉色の甜心
    2020-11-28 15:05

    No, unless you return the function:

    def func1():
        def func2():
            print("Hello")
        return func2
    
    innerfunc = func1()
    innerfunc()
    

    or even

    func1()()
    

提交回复
热议问题