Operators in Python Part 1

Lesson Details:
September 17, 2020

Video Transcription: In this lecture we are going to talk about operators in Python this video is brought to you by Appy Pie’s Academy, See operators are symbols that tell computer what operation is to be performed on operands by operands we mean constant values or variables upon which we want to do the operations for example 100 plus 200 here 100 is the operand 200 is also the operand and plus is the operator similarly 100 greater than 200 I am comparing 100 with 200 by writing 100 greater than 200 so here also 100 and 200 they are operands and greater than is the operator right so see as far as types of operators are concerned on basic level there are three types arithmetic operators relational operators logical operators as far as arithmetic operators are concerned we have got a host of them plus operator minus multiplication division then there is modulus operator with the percent idle symbol C you can see it at in the list at number 5 so what modulus operator does is it gets the remainder after division I will give you an example after a while then double star symbol at 6 number this is for exponentiation and double slashes is for float reason relational operators are basically used to compare operands so it's greater than greater than or equal to less than less than or equal to W equal to is used to compare the Equality of two operands then there is at-6 number there is not equal to logical operators there are three logical operators and or not I will explain about logical operators after a short while from now but first let me show you arithmetic operators how they are used it's very simple you are already familiar with this 10 plus 2 is equal to 12 10 minus 2.0 your tent and 2.0 they are the operands minus symbol is the operator or thematic operator of course and in 2 to 20 then see at number 4 18 modulus for this percentage symbol is called modulus or modulo this operator as I have told you gives the remainder so when we will divide 18 with 4 we will be getting 2 as the remainder so we are not talking about the quotient we are talking about the remainder after the division then at number 5 I have written 5 2 times multiplication symbol that it stars then 3 so that means 5 raised to power 3 it will give you 125 then at 6 we have written 18 double slashes 4 so this is going to do the flowed visa so when we will divide it in with 4 we are we tend to get four point something but we will get 4 now important point for modulus operator there are two points both operands should be integer sign of numerator is always considered in operation for example minus 10 modulus 4 will give you minus 2 but if it is 10 modulus minus 4 that means denominator is having negative symbol minus symbol then we are not going to get minus 2 we are going to get 2 only relational operators as I told you earlier also relational operators are used to compare to our friends the output of these operators are always true or false so 2 or false they are called boolean values relational are greater than greater than or equal to less than less than equal to double equal to not equal to etcetera now see by example you can come to know about the use of these relation operators like 10 greater than 20 will yield false because this condition is false similarly 20 greater than or equal to 10 will yield true 10 greater than or equal to 10 will yield true and double equal to 10 means we are comparing the Equality of the first operand 10 with the second operand then of course both are equal so it will yield true then 20 not equal to 20 will yield false because 20 is equal to 20 so this is 20 is not equal to 20 so it will yield false okay now we come to logical operators logical operators are used to either check a combination of conditions or to negate the logical state of a condition let me explain it this way there are three there are three logical operators and or not I am sorry I have mistakenly I have written relational operators these are not relation operators or logical operators and or not so I am sorry for that now see see examples 10 less than 20 and 5 less than 2 we are combining two conditions by using and now when I would write 10 is less than 20 this condition is going to be this condition is going to be true and 5 is less than 2 this second condition is going to be false because 5 is not less than 2 so that means one condition is true and second condition is false another condition is false so if either of the condition is false the overall output would be false so it will yield false because both the conditions they have been combined with this operator add similarly in the next example I am writing 20 greater than 10 and 5 greater than 2 now see both the conditions are 2 20 is greater than 10 5 is greater than 2 okay so it will ultimately yield true now as far as our operator logical operators concerned either of the condition can get true in order to have the final evaluation as true what I mean to say is there is need to that is need to need for only one condition to be true others can be false so twenty greater than ten this condition is true or five less than two this condition is false but even then the overall the final result will be true because one condition is true similarly twenty less than ten or five greater sorry five less than two now in this case both the conditions are false right so because both the conditions are false the final result is going to be false now the last one is very important this is called negation operator and no T not when I am writing not 100 greater than 200 now not operator is used this logical operator is used to negate a condition what I mean to say is we will check the condition of condition is false it will the result will be true if the condition is true the result will be false now 100-grit is greater than 200 this condition is false but because we have prefixed it with the logical operator not which is also called negation operator the result that will be produced is true. 


loader
Course content