关于带有参数的python调用函数的问题

时间:2018-09-27 10:31:49

标签: python

每个人都可以解释为什么我打电话给fibDict(n = 10, {})会出错,但是fib(10, d = {})却没出错吗? 谢谢!

def fibDict(n, d):
    if n in d.keys():
        return d[n]
    elif n == 0:
        d[n] = 0
        return d[n]
    elif n == 1:
        d[n] = 1
        return d[n]
    else:
        d[n] = fibDict(n-1, d) + fibDict(n-2, d)
        return d[n]

0 个答案:

没有答案