-1
私はPythonプログラミングの初心者です。私は、再帰ループ内で何が起こっているのか理解するのに役立つ再帰のための小さなスクリプトを書いた。しかし、再帰が終了した後、私はスクリプトの最後の部分とそれが何をしているのか分かりません。ここに私のスクリプトです。Python終了後に再帰は何をしていますか?
def test(n, m, p, k):
print(n, m, p, k, 'This is the value coming in.')
if n > 0:
print(n, m, p, k, 'This is before recursion.')
test(n-1, p, k, m)
print(n, m, p, k, 'This is when n = 1.')
Iは>>>試験(5、10、20、30)
5 10 20 30 This is the value coming in.
5 10 20 30 This is before recursion.
4 20 30 10 This is the value coming in.
4 20 30 10 This is before recursion.
3 30 10 20 This is the value coming in.
3 30 10 20 This is before recursion.
2 10 20 30 This is the value coming in.
2 10 20 30 This is before recursion.
1 20 30 10 This is the value coming in.
1 20 30 10 This is before recursion.
0 30 10 20 This is the value coming in.
1 20 30 10 This is when n = 1.
2 10 20 30 This is when n = 1.
3 30 10 20 This is when n = 1.
4 20 30 10 This is when n = 1.
5 10 20 30 This is when n = 1.
なぜ最後の5つの印刷機能がNにN = 1から上がっされる実行時にこれが結果であります= 5?
ああ、わかりました。ありがとう! – Kenneth