Boolean logic is a fundamental part of programming, so we are going to have to write boolean logical expressions in our programs. We've shown you how to do this mathematically, but now it's time to figure out how to do it in Python. Here's a simple program that demonstrates how to write logical expressions in Python. All right, first we have to actually understand how to write the booleans true and false. And in Python, hey this is pretty easy. It's just the words true and false, but you have to capitalize them. Okay, so, as you can see here, I've assigned True to value1 and False to the variable value2. Okay, so, true and false are just boolean values. You can use them just like we use numbers in the past. Okay, and you can assign them to variables and then the variables will hold those boolean values. You can see here, when we run this, Python prints out the words True and False for us because value1 and value2 hold those values of True and False. These are not strings though. These are actual boolean values, so I can do logical operations on them. So, let's start with NOT, okay. Let's do the boolean NOT here. We see that. Okay? As expected, when I use NOT on value1, which was originally True, I get False. And NOT value2, which was originally False, I get true. Okay, so you can see that Python uses the English language word for the NOT operation. Let's look at logical AND. Okay, again, Python uses the English language word here, AND to be logical AND, so I'm going to do value1 and value1. So that should be True and True, which should that evaluate too? You knew it's True, right? Okay. Let's see what happens. Yes, we get true there. All of the others 2 are False. Why? Because value2 is False. And when you do logical AND with one False value, you always get False. All right? Moving on. Let's look at logical OR. Yet again, Python uses the English language word OR to represent the logical OR operation. And when we do this we're going to get True, True, False. Okay, value1 was True so when I have value1 OR'd with anything else, either itself or value2, we get True. Value2 OR'd with value2. They're both False. Okay, we get False. All right? Makes sense. Now, I can't stress enough that it's very nice that Python uses English language words here. Right? It's very easy to see what's going on in your program. You have the words True and False to represent the boolean values. We have the English words NOT, AND and OR to represent the Boolean operations. OK? And so, when you look at the program it's fairly straightforward what's going on. Now, so far these have all been simple boolean expressions with only one boolean operator, okay? Just like with arithmetic we can also have compound expressions with multiple boolean operators. So let's take a look at that. All right, I added two new values, value3 and value4, made them both True and now I have a more complex compound boolean expression here. And we run it and it evaluates to True. A couple of things. First, you should try this yourself. Okay, you should plug in the values of value 1, 2, 3 and 4 into that expression, evaluate it yourself and see what you get. Okay, check on Python, make sure Python knows what it is doing. All right? You also want to make sure that you know what you're doing. Okay, that you can understand how this gets evaluated and how it evaluates to True. All right, the second thing. We also have to worry about operator precedence here, just like we did with arithmetic expressions. Okay, these do not all have the same precedence. If you go back to the Python documentation and look for operator precedence, you will find the boolean logical operators on that table and you'll find that NOT has a higher precedence than AND, and AND has a higher precedence than OR. So, if we just write an expression, it might not evaluate in the way that you expect it to. So, just as I recommended with arithmetic expressions, I also recommend strongly here that you always use parentheses in your boolean expressions. Okay, so you'll see that I use parentheses here because I wanted to change the way in which this was evaluated. And so, make sure that you put parentheses so that it gets evaluated in exactly the way that you want it to be. So, now we've seen how we can write boolean logical expressions in Python. Hopefully, you found it to be relatively straightforward. Right? The fact that Python uses the English language words true, false, not, and and or, makes it pretty easy to both read and write these expressions.