0

在scheme中,我们可以使用功能码:local,使用起来很方便。那么,python中有没有类似的代码?

4

1 回答 1

2

我怀疑您在问是否可以在 python 中的函数中定义具有与非嵌套函数类似的行为的函数。

答案是,是的。

def some_function():

    def some_other_function():
        # code that does stuff
        pass

    # code that does stuff
    pass

这两个函数的功能相同,只是 的范围some_other_function在 的范围内some_function

于 2012-11-12T00:07:00.543 回答