使用布尔值的If语句的语法 [英] Syntax for an If statement using a boolean
本文介绍了使用布尔值的If语句的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近才加入python3 HypeTrain.但是我只是想知道如何在布尔值上使用if语句.示例:
I just recently joined the python3 HypeTrain. However I just wondered how you can use an if statement onto a boolean. Example:
RandomBool = True
# and now how can I check this in an if statement? Like the following:
if RandomBool == True:
#DoYourThing
而且,我可以像这样切换布尔值吗?
And also, can I just switch the value of a boolean like this?
RandomBool1 == True #Boolean states True
if #AnyThing:
RandomBool1 = False #Boolean states False from now on?
推荐答案
您可以更改所有布尔值.至于是否:
You can change the value of a bool all you want. As for an if:
if randombool == True:
可以,但是您也可以使用:
works, but you can also use:
if randombool:
如果要测试是否为假,可以使用:
If you want to test whether something is false you can use:
if randombool == False
但您也可以使用:
if not randombool:
这篇关于使用布尔值的If语句的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文