我刚加入python3 HypeTrain。但是我只是想知道如何在布尔值上使用if语句。例:
RandomBool = True
# and now how can I check this in an if statement? Like the following:
if RandomBool == True:
#DoYourThing
而且,我可以像这样切换布尔值吗?
RandomBool1 == True #Boolean states True
if #AnyThing:
RandomBool1 = False #Boolean states False from now on?
您可以随意更改布尔值。至于是否:
if randombool == True:
可以,但是您也可以使用:
if randombool:
如果要测试是否为假,可以使用:
if randombool == False
但您也可以使用:
if not randombool:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句