如何在Python中使用比较和“如果不是”?

2024-03-17

在我的一个程序中,我怀疑我是否正确使用了比较。我想在做某事之前确保( u0

if not (u0 <= u) and (u < u0+step):
    u0 = u0+ step # change the condition until it is satisfied
else:
    do something. # condition is satisfied

你可以做:

if not (u0 <= u <= u0+step):
    u0 = u0+ step # change the condition until it is satisfied
else:
    do sth. # condition is satisfied

使用循环:

while not (u0 <= u <= u0+step):
   u0 = u0+ step # change the condition until it is satisfied
do sth. # condition is satisfied
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在Python中使用比较和“如果不是”? 的相关文章

随机推荐