0

I have following lines of code. I am a newbie to python.

def fibo(n):
 a, b = 0,1
 while a < n:
    print a,
    a,b=b,a+b
n = raw_input("Enter a no:")
fibo(int(n))

I am not able to understand following code.

a,b=b,a+b

Is it equivalent to following?

a = b
b = a+b

I tried that, but didn't get expected results. I understand that its a multiple value assignment in a single line. please correct me if I am missing anything.

Vinod Chandak
  • 373
  • 1
  • 6
  • 15
  • yep, you're correct. – Avinash Raj Feb 03 '15 at 06:54
  • Also see: http://stackoverflow.com/questions/21047524/how-does-swapping-of-members-in-the-python-tuples-a-b-b-a-work-internally and http://stackoverflow.com/questions/2623086/is-a-variable-swap-guaranteed-to-be-atomic-in-python – Jon Clements Feb 03 '15 at 06:57

0 Answers0