检查 Python While 循环中的值是否仍然保持不变

Red*_*vet 2 python loops imperative-programming while-loop python-2.7

我想知道是否有一种优雅的方法来查看是否可以检查在 while 循环中不断变化的值,并在该值停止变化并保持不变时停止 while 循环。

例如:

Value = 0
while True:
    value changes everytime
    (if value still the same break)
Run Code Online (Sandbox Code Playgroud)

luo*_*luo 5

这条路怎么样?顺便说一句:修复你的拼写错误while不在Whilepython 中。

value = 0
while True:
    old_value, value = value, way_to_new_value
    if value == old_value: break
Run Code Online (Sandbox Code Playgroud)