Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在scheme中,我们可以使用功能码:local,使用起来很方便。那么,python中有没有类似的代码?
我怀疑您在问是否可以在 python 中的函数中定义具有与非嵌套函数类似的行为的函数。
答案是,是的。
def some_function(): def some_other_function(): # code that does stuff pass # code that does stuff pass
这两个函数的功能相同,只是 的范围some_other_function在 的范围内some_function。
some_other_function
some_function