I just recently joined the python3 HypeTrain. However I just wondered how you can use an if statement onto a boolean. Example:
JavaScript
x
5
1
RandomBool = True
2
# and now how can I check this in an if statement? Like the following:
3
if RandomBool == True:
4
#DoYourThing
5
And also, can I just switch the value of a boolean like this?
JavaScript
1
4
1
RandomBool1 == True #Boolean states True
2
if #AnyThing:
3
RandomBool1 = False #Boolean states False from now on?
4
Advertisement
Answer
You can change the value of a bool all you want. As for an if:
JavaScript
1
2
1
if randombool == True:
2
works, but you can also use:
JavaScript
1
2
1
if randombool:
2
If you want to test whether something is false you can use:
JavaScript
1
2
1
if randombool == False
2
but you can also use:
JavaScript
1
2
1
if not randombool:
2