
上QQ阅读APP看书,第一时间看更新
Understanding boolean expressions
Boolean expression syntax is a little bit weird or unusual, at least in Python:
print (1 == 3)
The output of the above code is as follows:
False
As usual, we have the double equal symbol that can test for equality between two values. So does 1 equal 3, no it doesn't, therefore False. The value False is a special value designated by F. Remember that when you're trying to test, when you're doing Boolean stuff, the relevant keywords are True with a T and False with an F. That's a little bit different from other languages that I've worked with, so keep that in mind.
print (True or False)
The output of the above code is as follows:
True
Well, True or False is True, because one of them is True, you run it and it comes back True.