Ok, I'm going through the documentation (the informal introduction to 2.0 part) and I'm a little confused about defining functions. It gives this example of the Fibonacci sequence:
>>> def fib
: # write Fibonacci series up to n
... "Print a Fibonacci series up to n"
... a, b = 0, 1
... while b < n:
... print b,
... a, b = b, a+b
...
>>> # Now call the function we just defined:
... fib(2000)
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
Now keep in mind, I'm moving to python from C++
Ok, first of all the Fibonacci function is recursive right? Well I don't see any calls to fib within the function, what's with that? =P
Next, what does "a, b = 0, 1" do? To me it would seem it declares a, assigns b to 0, and then prints one or declares it or something =P
And why is it when I try, "a = 0, b = 0, 1" it says it can't assign to literal? I just typed that in trying t figure out what the a, b = 0, 1 did. [sig][/sig]
>>> def fib
... "Print a Fibonacci series up to n"
... a, b = 0, 1
... while b < n:
... print b,
... a, b = b, a+b
...
>>> # Now call the function we just defined:
... fib(2000)
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
Now keep in mind, I'm moving to python from C++
Ok, first of all the Fibonacci function is recursive right? Well I don't see any calls to fib within the function, what's with that? =P
Next, what does "a, b = 0, 1" do? To me it would seem it declares a, assigns b to 0, and then prints one or declares it or something =P
And why is it when I try, "a = 0, b = 0, 1" it says it can't assign to literal? I just typed that in trying t figure out what the a, b = 0, 1 did. [sig][/sig]