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
Post a Comment