1.6 Operators in Python | Python Full course 2024 #learnpythonin2024 #mlwithakansha

Akansha Yadav walks through Python operators in a Jupyter notebook. She demonstrates arithmetic operators with number1=10 and number2=3, shows how comparison operators return True or False, and explains logical operators (and, or, not) using Boolean variables.
Chapters
Ladies and gentlemen, in this video we will discuss about operators in Python. Now, what are operators in Python? Operators are those things which helps us up— perform some operations, mathematical operations, onto the numbers or strings or any data type that you wanted to. So there are different, different types of operators. So one of them is the arithmetic operator. So arithmetic operators is like add, or we have subtraction, or we have division, then we have multiplication, floor division, and so on. So let's learn it one by one. That what are all those automatic operators. Apart from automatic operators, before we begin with our notebook of Python, let me tell you other types of operators as well. Another one we have is the comparison operator. The comparison operators are those operators which helps us to compare values. It also in return gives us two types of values. It either can be true or either it can be false. So there are certain comparison operators as well, like equal to, not equal to, greater than, less than, less than equal to, like this. Another type of operator which is important to you, like for you to learn, is the logical operator. Logical operators are those operators which helps us to perform logical things on it. Like if there are two conditions and you wanted to compare them, that whether condition 1 is— 1 and 2 are true or not. In case it is true, then this will happen, otherwise no. So this 'and' in between is the logical operator. So there are certain logical operators like 'and', or not. So these are few operators we will be discussing in this video. So I'm going to create a new file, let's say operators, in ipynb. Let us select the kernel. So first is the arithmetic operator. Now, what are automatic operators? Automatic operators are for basically, uh, mathematical things, like all the mathematical operations you can do using these automatic operators. So first is our— I will just create another, okay, addition, which is add symbol. Then we have subtraction, multiplication, division. Then we have floor division, which is double division symbol. Then we have modulo, which is a percentage symbol. And then we have, which is double asterisk symbol, which is exponent. So all these are the arithmetic operators. They are basically 7 in numbers. So let's write down a basic thing, like a basic program. I have 2 variables, number1, which is, let's suppose, 10. Then we have number2, which is, let's suppose, 3. So I have 2 values, number1 and number2. I will operate all these things for you. So number1 plus number 2 is going to give us the addition, which I'm going to print. Addition is— and so on. Same way I will perform subtraction and other operations. So I'm just going to change some things. Like in place of subtraction, I will— in place of addition, I will write subtraction. In place of addition, I'm going to write multiplication, where I will be writing multiplication symbols. Then I'm going to use the same statement and will edit it for division. So these are the basic things that we usually use in Python, like in maths. And are same in Python. Then we have floor division. So in division we get the normal division values, but in place of floor division you will get the values which are just the whole number. So in this case we have two values, 10 and 3. If we are going to divide 10 by 3, we will get— we are getting 3.333. So in case you just want the output which is a whole number, I don't want a value which are after decimals, so I will— I can just get it using floor division. So I will use the same statement The floor division value is double division symbol. So here I'm getting 3, which means it won't be giving you any decimal value out of— like, after decimal there won't be any value. It will just give you the whole number. In case you wanted to check what is the decimal— what is the remainder of the same thing, if I'm getting 3 as a whole number, then what is the remainder? So if you wanted to know the remainder, you will use a percentage symbol, which we also say modulo or modulus. In case we will divide 10 by 3, we will get 1 as a remainder. And here also we are getting exponent is nothing but to the power of something. Exponent is num1 to the power of num2. It means number 1 to the power of number 2, which is 10 to the power of 3. So the 10 to the power of 3 is 1,000. So these all are the arithmetic operators. Next type of operator that we have is our comparison operator. So comparison operator Comparison operators are to compare the values. So let's compare the values which we already have, number 1 and number 2. So I want number 1 is equal to equal to number 2. Is it true or false? No, we have 10 as a number 1 and 3 as a number 2, which are not equal. So in this case, we're getting false. So if you wanted to check whether they are not equal to, if you wanted to write not equal to, you will use exclamation symbol and equal to. It's true because they are not equal. So not equal to is exclamation symbol and not equal to. So there are certain comparison operators. So, so till now we have discussed about equal to, not equal to. And we have less than, greater than, less than equal to, greater than equal to. So if I'm going to check number 1 is greater than number 2, yes, it is true. Now I'm going to check number 1 is less than num2 should be false. I'm going to check num1 is greater than equal to num2. It's true. Yes, 10 is not equal to this, then it's greater than. num1 is less than equal to num2, it's false. So these are all the comparison operators in Python. The values that you are getting, true and false, we call them as Boolean values. Boolean values are just true/false values. Another type of operator that we have is logical operator. So we have 3 logical operators: AND operator, OR operator, and we have NOT operator. So let's suppose is_india is equal to true. I'm writing, then I have another variable is_uk is equal to false. I have two values: is_india is equal to true, is_uk is equal to false. I'm going to check it. and_ result is equal to isIndia and is_UK. So I have another variable which is andResult, and then I'm going to create or_result is equal to is_India or is_UK. Then I'm going to create another variable not_result result is equal to India not. In case of not operator, we use it in front of the variables. Now I'm going to print the variables one by one. So OR result, AND result, and NOT result. NOT is basically the opposite of what is happening. AND is when both the conditions are true, it will give you the true value. When both the conditions— when you want one of the condition to be true, it will give you the true value. When you want none of the condition to be true, you just want the opposite of the condition, you are getting you will get it using the NOT operator. So in case of AND, you can use it when you have two conditions and you want both the conditions to be true to something— for something to happen. Then you can use AND operator. If you want something to happen when one of the conditions is true, then you can use OR condition— OR operators. And NOT operator is basically when you want the opposite of something. So if output is true, it will give you false. If the output is false, it will give you true. This is how NOT operator works. So use different values and explore all 3 types of operators of Python.










