Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python如何运行内部函数?_Python_Function_Python Decorators - Fatal编程技术网

Python如何运行内部函数?

Python如何运行内部函数?,python,function,python-decorators,Python,Function,Python Decorators,我很难理解Python中如何运行内部函数。请查看以下代码片段: def f(a, b): return a + b def outer(f): def inner(x, y): if not isinstance(x, int) and not isinstance(y, int): raise TypeError('Please provide integer for both arguments') return f(

我很难理解Python中如何运行内部函数。请查看以下代码片段:

def f(a, b):
    return a + b

def outer(f):
    def inner(x, y):
        if not isinstance(x, int) and not isinstance(y, int):
            raise TypeError('Please provide integer for both arguments')
        return f(x, y)
    return inner
我只是不知道什么时候运行
internal
,它如何返回带有
internal
参数的函数
f
,最后返回
internal
就是返回
f


当上述代码被传递给解释器时,有人能告诉我们Python解释步骤的方式吗。

您的缩进似乎已关闭。在您提供的代码中,
internal
从未运行过。除非缩进被关闭,
internal
不会返回任何内容。缩进现在已修复。我想一步一步地解释一下程序是如何运行的,特别是,看看答案,还有,请注意,上面的程序只定义了两个函数,从不调用一个函数。因此,“when is
internal
run”的答案永远不是。