Understanding how recursive functions work

后端 未结 18 1011
野性不改
野性不改 2020-11-22 07:08

As the title explains I have a very fundamental programming question which I have just not been able to grok yet. Filtering out all of the (extremely clever) \"In order to

18条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 07:43

    I was having hard time to understanding recursion then i found this blog and i already seen this question so i thought i must have to share . You must read this blog i found this extremely helpful it explain with stack and even it explain how two recursion works with stack step by step. I recommend you first understand how stack works which it explain very well here : journey-to-the-stack

    then now you will understand how recursion works now take a look of this post : Understand recursion step by step

    Its a program :

    def hello(x):
        if x==1:
            return "op"
        else:
            u=1
            e=12
            s=hello(x-1)
            e+=1
            print(s)
            print(x)
            u+=1
        return e
    
    hello(3)
    

提交回复
热议问题