Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Boolean values in Python are the special True and False objects.
So if I say 5 == 5, I get the True value back.
And if I say 7 < 5, I get the False value back.
So True and False are special values. They're actually of a Boolean class.
If I say, type(True)
So if I say True and False, like that, I get False. If I say True and True, I get True. If I say True or False, that's True. If I say False or False, that's False. So the and, and the or operators, the ones that are spelled out as words, are especially Boolean operators. These are different then the bitwise, and, or.
So if I say True & True, like this, I get True. The difference is that's a bitwise operator. I'm doing bitwise arithmetic, as opposed to simply Boolean arithmetic. I'm doing bitwise arithmetic, which is different then the Boolean operators. So the Boolean operators are and and or spelled out. And they're useful for things like this. If I have, say, two values a, b and they're 0, 1, and if I have another two values x, y and they're spelled out say 'zero', 'one', and I say x < y, which of course is False, and a < b, which of course is True, so I could say, if I wanted to, if a < b and x < y, of course, that won't be True print('yes') else: print('no') and it prints no.
And so here I'm combining these two Boolean values. a < b, will result in a Boolean value of True. x < y results in a Boolean value of False. And so if they're both True, which they're not, we would print('yes'). And if they're not both True then we'll print('no'). So this is where you use the Boolean operators. You use them when you're operating on two Boolean values. And you're get these Boolean values typically in a comparison operation, like less than, or greater than, or one of the comparison operators that we covered in our movie on comparison operators.
So that's the use of the Boolean operators, as opposed to the bitwise operators.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98575 Viewers
61 Video lessons · 85870 Viewers
71 Video lessons · 69760 Viewers
56 Video lessons · 102063 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.