Transcript for:
Understanding Logical Operators in Programming

hi in this video we're going to introduce logical operators so logical operators let us connect and modify Boolean Expressions The Logical operators are not represented by an exclamation point or represented by the two vertical lines those are on the right side of the keyboard and and represented by two Amper Sands so let's look at the not operator so what the not operator does is gives you the opposite of whatever ever the Boolean expression is so if x is true then not X is false if x is false then not X is true the and operator so the and operator gives you a true value if both of the things on the side of the and operator are true so if x is true and Y is true then X and Y is true but otherwise it's always false so if one or the other is true it's false and if they're both false then it's false so the and operator returns true only if both sides are true now the or operator the or operator returns true if one or the other is true so if they're both true then X or Y is true if x is true and Y is false then X or Y is true if x is false and Y is true then X or Y is true but if they're both false then X or Y is false so let's look at an example with a not operator so say I declare a Boolean called light on and set equal to true you can see that our box holding that value is is has the value true and then in the next line we say light on gets the value of not light on so now in our box light on has the value false and light is off what that not is really doing is is switching the value that it gets whatever the opposite of what it had before let's go look at this in our code editor so here I have a light switch program and I set light on to be true and then I print out the value of light on and it says true and now we'll say light on gets the value not light on so what we're doing there is assigning it the opposite values so we're switching the light so I will run this program and we'll see that it's true and then it's false and we'll we'll copy those lines and run that code one more time and on here right on line 15 it will get the opposite value again and go back to true so that's one example of using the not operator now you'll get to write some programs using and or and not