In <f99a156b-56b4-41f4-9599-0dcc31a47...@v9g2000pri.googlegroups.com> kangshu...@hotmail.com writes:
> Hi everyone > I just study python for a few time. > Now I have a problem and I holp someone can help me. > There is a piece of code: > def fib(x): > if x==0 or x==1: return 1 > else: return fib(x-1) + fib(x-2) > Could you explain how it works? > Thanks for you help. > Vince When a function calls itself, as fib() does, it's called recursion. http://en.wikipedia.org/wiki/Recursion_(computer_science) Basically the fib() method keeps calling itself with smaller and smaller arguments until it gets 1 or 0. -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" -- http://mail.python.org/mailman/listinfo/python-list