简单的例子.两种方法,一种叫另一种方法:
def method_a(arg):
some_data = method_b(arg)
def method_b(arg):
return some_data
Run Code Online (Sandbox Code Playgroud)
在Python中,我们可以def在另一个内部声明def.因此,如果method_b需要并且仅从中调用method_a,我应该method_b在内部声明method_a吗?像这样 :
def method_a(arg):
def method_b(arg):
return some_data
some_data = method_b
Run Code Online (Sandbox Code Playgroud)
或者我应该避免这样做?