What is the different between these two ways for declaring variables in python? -


while printing fibonacci series

a,b,c=1,1,1 while (c<7):   print(b,end=" ")   a,b,c=b,b+1,c+1 

the output >> 1 2 3 5 8 13

and when tracing code found result >> 1 2 4 8 16 32

this output resulted declaring variables in way

a,b,c=1,1,1 while (c<7):   print(b,end=" ")   a=b   b=a+b   c=c+1 

so difference between these 2 different ways in declaring variables

this line:

a,b,c=b,a+b,c+1 

is equivalent to:

new_a = b new_b = + b new_c = c + 1  = new_a b = new_b c = new_c 

Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -