In [1]: n = '4' != 'e'
In [2]: n
Out[2]: True
In [3]: while n = '4' != 'e':
File "<ipython-input-12-1aa2b5c52181>", line 1
while n = '4' != 'e':
^
SyntaxError: invalid syntax
Python中的表达式n = '4' != 'e'
具有布尔值True
。但是,当在while
循环中使用时,Python 2.7抱怨将其解析为循环条件。为什么会这样?