我是一名编程初学者,我在尝试一些函数。我有两个变量(整数)和一个将变量加1的自创建函数。我想在一个while循环中运行该函数,在该循环中,该函数应继续向变量加1,直到其中一个变量达到一定数量为止,但它以仅使用一次函数的无穷循环结束。我怎么了?
json_encode($searchFilters)
答案 0 :(得分:2)
将返回的变量从test()
分配到aa
和bb
:
aa = 2
bb = 5
def test(aa, bb) :
aa = aa + 1
bb = bb + 1
return aa, bb
while aa < 6 :
aa, bb = test (aa, bb) # <-- assign returned variables to aa, bb
print (aa, bb)
打印:
6 9