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

rest - Spring boot: Request method 'PUT' not supported -

php - Magento - Deleted Base url key -

symfony - imagine_filter() not generating the correct url in LiipImagineBundle -