edo1z blog

プログラミングなどに関するブログです

再帰? (Python)

これ再帰?

def testdef(x):
    testList = []
    testList.append(x*2)
    if x >0: testList += testdef(x-1)
    return testList


testdefに10を入れると、[20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0]が出てきます。

これ再帰でしょう??初めて再帰をやった!?お恥ずかしいです。