Python-- from continuous assignment to Feibolaqie series

Python has a very simple assignment statement usage is continuous assignment.

  To respectively to the two variable assignment, my first thought was as follows:

1 a = 1
2 b = 2

  But in fact python also provides a more concise wording as follows

1 a , b = 1 , 2

  Then we can understand the natural order of evaluation, a = the first digit 1, b = 2 the second digit. But in fact not just the case.

  Continuous assignment moderate right-hand side are actually local variables, rather than the true value of the variable itself. When the right side of the equal sign is the value, of course, to do so without problems. But if the right is the expression contains a variable, it will adopt the sentence before the code as of a date, the value of each variable represents the assignment calculation. Such as

1 a = 0
2 b = 1
3 a , b = b , a + b

  Result of the above code is run, a = b = 1, b = a + b = 0 + 1 = 1, the output of a = 1, b = 1, and is not the hottest almost a = b used in a calculation. This is a pit!

  Finally easily affixed with a number of columns generated Feibolaqie, stickers because he is actually written in python only five lines! This is too easy!

1  # generation "Feibolaqie number of columns." 
2  # Fibonacci number refers to a number of columns is 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 
3  # 89, 144, 233,377,610,987,1597,2584 , 4181,6765,10946,17711,28657,46368 ........ 
4  # this series from the beginning of paragraph 3, each of which is equal to the sum of the first two. 
. 5 I = 0
 . 6 J =. 1
 . 7  for _ in Range (20 is):    # output before 20 
. 8      I, J = J, I + J
 . 9      Print (I, End = "   " )

 

Guess you like

Origin www.cnblogs.com/HuangYuanAvril/p/11209334.html