Recursion function in Python

后端 未结 10 2175
庸人自扰
庸人自扰 2020-12-15 11:52

Consider this basic recursion in Python:

def fibonacci(number):
    if number == 0: return 0
    elif number == 1:
        return 1
    else:
        return          


        
10条回答
  •  孤城傲影
    2020-12-15 12:30

    Matthew and MArtjin are right but I thought I might elaborate:

    Python does stuff from left to right whenever it can. Exceptions to this rule are implied by brackets.

    in x*power(x, y-1): x is evaluated then power is evaluated

    While in fibonacci(number-1) + fibonacci(number-2), fibonacci(number-1) is evaluated (recursively, til it stops) and then fibonacci(number-1) is evaluated

提交回复
热议问题