Variable assignment in expressions

后端 未结 4 1883
傲寒
傲寒 2021-01-16 13:36

Here is my code to generate values in the fibonnacci sequence below 10,000,000.

  3 fibs = [1,1]
  4 while((x = fibs[-1] + fibs[-2]) <= 10000000):
  5             


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-16 14:24

    The reason for not allowing assignment in Python expressions is a common, hard-to-find bug in those other languages, caused by this construct.

    Please check http://effbot.org/pyfaq/why-can-t-i-use-an-assignment-in-an-expression.htm

提交回复
热议问题