检查值在 While 循环 Python 中是否仍然保持不变 [英] Check if a value still remains the same in a While loop Python
本文介绍了检查值在 While 循环 Python 中是否仍然保持不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有一种优雅的方法可以检查是否可以检查在 while 循环中不断变化的值,如果值停止变化并保持不变,则停止 while 循环.
I want know if there is a elegant method for looking if a value that continually changes in a while loop can be checked and stop the while loop if the value stops change and remains the same.
例如:
Value = 0
while True:
value changes everytime
(if value still the same break)
推荐答案
这种方式怎么样?顺便说一句:修复你的拼写错误 while
在 python 中不是 While
.
How about this way? BTW: Fix your typo error while
is not While
in python.
value = 0
while True:
old_value, value = value, way_to_new_value
if value == old_value: break
这篇关于检查值在 While 循环 Python 中是否仍然保持不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文