使用布尔值的 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?
推荐答案
您可以随心所欲地更改 bool 的值.至于如果:
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屋!
查看全文