can someone explain to me this python code. This is a code for Fibonacci sequence while b < 50: print(b) a, b = b, a + b
a, b = 0, 1
I have a link you can check out that might help you try this link it explains about Fibonacci sequence http://www.youtube.com/watch?v=Dq7ORUWwSMg&feature=c4-overview-vl&list=PL41C4760954570944
Python has the ability to do multiple assignment. It also fully evaluates the right hand side of the = before doing multiple assignment. Therefore, the swap function in Python is very easy: a,b=b,a This is what allows the a, b = b, a + b part of that code to work. The right hand side of b, a + b is evaluated fully and stored. Then a, b is changed to point at the new values, and the old values having nothing pointing at them go by-by.
Join our real-time social learning platform and learn together with your friends!