The return statement is used to return from a function i.e. break out
of the function. We can optionally return a value from the function as
well.
def test_function():
a = "hello"
return a # returns variable a
def test_function2():
a = test_function()
if a == "hello":
print(a)
else:
print("hello world")
test_function2()
你可以这样做。以函数作为参数,并以
a
作为参数调用它。现在您可以传递任何需要作为输入的函数,而无需在test_function
外部公开a
。你知道吗相关问题 更多 >
编程相关推荐