Hi, this lecture is all about true and false values. Also known as Boolean values. In this lecture we will explore the Pythons type bool and operators that we can apply to Boolean values. Earlier we used Pythons arithmetic operators like multiplication and subtraction And now we're going to use some of Python's comparison operators. For example, let's compare values three and four using the less than operator. When this expression is evaluated we're going to get our true value or false value back. The type of value that we get is type bool. That's a good pair of three with eight. Asking you if three is greater then eight. And it's not so the value that this expression evaluates to is false. When you evaluate eight greater then three, we get true. And if we were to evaluate three point five greater then or equal to three point four. It's also true. Let's compare two ints, seven, seven. Notice that the operation that we're performing now is the equality operation. And, we need to use two equal signs, not one to signify equality. That's because the single equals sign is already used for the assignment operation. Seven is equal to seven. How about seven and seven point zero. A type int operand with a type float operand. This is also true. Let's assign a couple of variable values. X gets seven, Y gets eight, and now we can apply the same equality operator to two variable operands. First, we look up the value that X refers to, which is seven, and Y refers to eight, and then seven is compared with eight. Another operator's the inequality operator. You can check whether three is not equal to four, and that's True. Python also has three logical operators, which are operators that are applied to Boolean values, and yield Boolean results. The first logical operator that we'll use is a not operator, and we'll begin by creating a variable grade, and assigning it the value 80. So grade refers to 80. Now, let's write an expression that checks to see whether the grade is a passing grade. Is grade equal to or greater than 50? And that's true. We'll apply the not operator to that expression now So we're going to check to see whether grade is not greater than or equal to 50. The order that this expression is valuated works from inside out, so the grade greater than or equal to 50 part of the expression is evaluated first, and that gives the value of true. And then the not operator is applied to True. Something that is not True is False, and that's the result that we get back. And you can apply this not operator two times in a row. Saying that this is asking whether this is not not true, which is equivalent to just saying, is grade greater than or equal to 50. Next let's use the and operator. First, we'll make another variable named grade2 that refers to the value 70. And, now we'll write an expression involving both variables grade and grade2. This expression will check to see whether both of these are passing grades. So is grade greater than or equal to 50, and is grade2 also greater than or equal to 50. And evaluates to true if both operands are true. So first, this expression is evaluated, and it is true. So then, this expression is evaluated and it is also true, making this entire result a true result. Let's change the value of the variable grade for a moment and set it to 40. We'll rerun this Boolean expression involving the and, and check to see what we get. Because this first operand is false, the Boolean expression is false. And we don't even go on to check the second operands value. Now let's set grade back to 80, and this time change grade2 to be a failing grade. When this expression is evaluated, first this part of the expression is evaluated. And that's true, so we move on to evaluate this part of the expression, which is false. And so the expression evaluates to false. To summarize, and again, only evaluates true if both of its operands are true. Otherwise it evaluates to false. Finally, let's use the logical operator four which also applies to do operands. We'll start by assigning to the grade in grade2, two passing grades. And now we'll write the same expression as before, replacing the and with an or. This expression will evaluate to true if at least one of the operands in true. So in this case, we get true. Now let's assign to grade a failing grade and reevaluate the expression. As I will first evaluate the first part of this expression and determine that it is false. So we will go on to evaluate the second part of the expression which is true and because at least one operand is true. The expression evaluates to true. If we set grade to a passing grade and grade2 to a failing grade, then when the expression is evaluated it works as follows. Because grade is a passing grading the expression is evaluated to true at this point, without even having to go on to look at the second operand. So to summarize a boo, the Boolean operator or evaluates to true If it at least one of its operands is true and it evaluates to false otherwise. Now let's combine the operators into single expressions. I've assigned grade and grade2 passing grades of 80 and 90. And I'd like to evaluate this expression. And then applied not to grade greater then or equal to 50, or grade2 greater than or equal to 50. And there are a couple of different ways that we can interpret this expression, depending on order of presidence. The first would be to have the or operator applied. First and I'll use parentheses to signal that, followed by the not operator. The second would be to have the not operator apply first to the first part of the expression and then the or operator apply second. So not first, followed by or, or first followed by not. Let's evaluate the expression, and see what happens. The value that the expression evaluates to is true. Let's use the parentheses to see which of the two operators applied first. We'll begin by putting the parentheses around the or part of the expression. Ensuring that or applies before not. And when we do that the result is false. So, that's not what happened when we left out the parenthesis and that means that that's not the order of precedence. Instead the order of precedence is that not is applied first as I can show here. Followed by or. The order of presence for logical operators is not and and then or. And when we're working with multiple logical operators within an expression, we can use parentheses to ensure that the operations apply in the order we'd like. Without having to worry about what the order of precedence is. So use parentheses to make the order of operations occur in the order that you want. Sometimes we'll use parentheses to make an expression more readable. For example, in this expression, the arithmetic operators have higher precedence than the Boolean operators, or logical operators. So these parentheses are unnecessary. But we include them for [UNKNOWN]. Instead we could have left off the parentheses and had the following. But some might find a little harder to read and understand.