擅长:python、mysql、java
<p>你可以这样做。以函数作为参数,并以<code>a</code>作为参数调用它。现在您可以传递任何需要作为输入的函数,而无需在<code>test_function</code>外部公开<code>a</code>。你知道吗</p>
<pre><code>def test_function(func = lambda a : None):
a = "hello"
func(a)
def test_function2(a):
if a == "hello":
print(a)
else:
print("hello world")
test_function(test_function2)
</code></pre>