【发布时间】:2016-11-20 06:32:24
【问题描述】:
我最近刚刚加入了 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?
【问题讨论】:
-
你试过看看发生了什么吗?
-
好吧,我确实声明了一个错误:(
-
"如果 Check6228 == False: UnboundLocalError: 在赋值之前引用了局部变量 'Check6228'"
-
你可能没有定义你的布尔变量。
-
赋值使用
=运算符,==检查相等。
标签: python python-3.x if-statement boolean