gpt4 book ai didi

python - 如何在python中使用比较和 ' if not'?

转载 作者:IT老高 更新时间:2023-10-28 21:56:51 27 4
gpt4 key购买 nike

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

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

关于python - 如何在python中使用比较和 ' if not'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4153260/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com