python - 调用另一个函数中定义的函数

标签 python python-3.x

我可以在 python3.2 的全局范围内调用嵌套在另一个函数中的函数吗?

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

是否有从 func1() 外部调用 func2() 的方法?

最佳答案

不,除非你返回函数:

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

innerfunc = func1()
innerfunc()

甚至

func1()()

关于python - 调用另一个函数中定义的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8457669/

相关文章:

python-3.x - Python/Tkinter : Cascading menus anchored at the right instead of the left

python - 由于比例因子和偏移量,导入 Python 时 NetCDF 数据精度下降

python-3.x - 使用 python 求解 x

django - 安装 Django 2.0.2 找不到版本

python - 从文本文件创建迷宫数组

python - DataFrame.index.levels 在削减数据帧后显示 "extra"值

python - 实际测试我构建的应用程序(Flask,Python)

python - 在 Python 中将频率转换为音符

python - 您如何使用 pd.read_clipboard 读取带有列表的数据框?

python - 在 Python 中旋转二维数组