I am not sure what would be the appropriate heading for this question, and this may also be a repeated question. Therefore, please be guided accordingly.
I am new to python programming. I have this simple code to generate Fibonacci series.
1: def fibo(n):
2: a = 0
3: b = 1
4: for x in range(n):
5: print (a, end=' ')
6:
7: a = b
8: b = a+b
9: print()
10: num = int(input("enter n value: "))
11: print(fibo(num))
If I executed the above code as is, I get the following result
enter n value: 10
0 1 2 4 8 16 32 64 128 256
If uncomment # 6 and comment lines # 7 and # 8, I get the actual fibo series.
enter n value: 10
0 1 1 2 3 5 8 13 21 34
I would like to know what is the difference between
a, b = b, a + b
and
a = b
b = a + b
Programming IDE: PyCharm Community 2017.3
source
share