Day-4 Python + MYQL FREE SESsions

A walkthrough of Python operators: arithmetic, comparison, logical, assignment, identity, and membership. The instructor demonstrates each with examples in Visual Studio Code, explains operator precedence, and previews calculator projects students can build once they learn conditionals and loops.
Chapters
Yeah, am I audible to you all? Yes. All right, so do you guys have any questions related to the concepts that we have covered or anything related to Python? No questions? All right, then let's proceed with the Next topic. I'm going to share my screen. Let me know once the Visual Studio Code is visible to you all. Yeah, it's visible.
Yes, yes, it's visible.
Okay, so now we will discuss about the operators in Python. So there are multiple operators that are in Python, and you can use them to make calculation related to the numeric or also in the sequence type. Okay, so the number one type of operator that we have is the arithmetic operator. Arithmetic operators means which can help you do some mathematical stuff like addition, subtraction, multiplication, and that also includes, uh, other operators like making division, floor divisions, and all. So let's first discuss about the arithmetic Arithmetic operator. So the number one operator is the addition, then we have subtraction, then we have division, and then we have multiplication. The next operator is the floor division, and the next one is the modulo, and then we have x. So these are the arithmetic operators. So the first one is for addition. This is very common because we have used it in mathematics as well. Then comes the subtraction, which is also very common. It means you wanted to subtract two things, then you can use the subtraction. This is division. This one is for multiplication. Now the next one is the floor division. And this is modulo, or you can also call it modulus. First, let's talk about the division. If I ask you that I wanted to divide 11 by— I wanted to divide 11 by 5, what will be the output? Yes, what will be the division if I'm going to divide 11 by 5?
2.5.
2.5. Simply, when we divide, it goes like the 11 number is placed in the middle and then 5 comes out, then 5 to 10 Then if we will subtract, we will get 1 as a remainder. Then again we can add a decimal point and we can add— we can add a 0 over here. So again, 2.2, correct?
Yes.
So this is one way of dividing where if I'm going to— wait, let me just— yeah, so if I'm going to again, like, obviously this is totally divisible, so in the end we are going to get 0. But at this time we have added a decimal point, that is why we are able to completely divide 11 by 5 and our output is 2.0. Now let's say I don't want to get the decimals, I just want the normal division. So if I'm going to divide 5 by 11, my output will be 2 as a question, and if I'm going to subtract 10, then 1 will be the remainder, correct?
Yes, yes.
So 1 is remainder, 2 is the quotient, and then we have the divisor and the dividing. In Python, if you specifically want to get this output, right, which is 2.2— if you wanted to get this output, then you have to use the division, okay? The division which we discussed, like this, the normal division is going to give you the output 2.0. If you want just this 2, which is without decimals, just the first digit, or you can say it as a first, uh, when you're going to first operand, right? If you wanted to get the first operand by the second, then you can use the floor division. And you want— you wanted to just know the remainder, that we are going to divide this particular number by this number, then what will be the remainder? If you wanted to focus on remainder, then you will go with the modulo. For modulus. If you wanted to focus on this quotient part, then you can go with the floor division. And when you want a complete division and you want the results also to— like, you are flexible that the results can be in the decimal points as well, then you can use this division one. Any question in this? Yeah, any question? It's simple, right? When you want the complete division output, go with the division. When you want only the quotient, it means without decimal, just the first operand, then you can go with the floor division. And when you are focusing on the remainder, then you have to go with the modulo. Now when we do— let me just erase everything. Okay, so up till now all these operators are clear to you? Next one is the power. When we say x to the power of y, so how do we write it? So x to the power of y, like this we write. Or if I say 2 to the power of 2, then it is— this is how you have to write it. And if you are saying 2 to the power of 4, then this is how you have to write it. So 2 to the power of something, then you have to use this double asterisk symbol, and this will calculate the power of something. It will— it is going to return the raised to the power result. Okay, so the first number is raised to the power of second, then it will automatically calculate it for you and will give you the output. Got it?
Yes, ma'am.
Whenever you are going to do the division, you will encounter zero division error. Like if you are trying to, you know, divide something, like if you are going to say 10 divided by 10— 10 divided by 0, sorry. So in this case, you will encounter one type of error which is zero division error. It means like the first number cannot be divided by 0. The division is not possible, so that is why you will get this error. Okay, now all these, uh, things like which I just discussed, like, okay, these are the mathematical operators. Then as in pi, as in mathematics, we have certain way, right? Do you remember the word mask concept? Yes, anyone who remembers the concept of BODMAS? Yes, what is it?
Uh, it's bracket of, uh, division, multiplication, addition, subtraction.
Yeah, basically in this manner the execution has to be done. Like whenever you are solving any equation, you have to follow this BODMAS method. Like first comes the bracket, then continuing with others. You have to follow it, uh, follow through all these BODMAS concepts, and then only you have to follow the entire expression. If you will fail to, you know, follow this, you will end up with the wrong result. Same way in Python also, there is a precedence of arithmetic operators. Precedence, like it is PEMDAS. I will just write it. This is the correct one which is followed in Python because it is— you can say that it is totally based on the terms which we use in Python. So first one is parenthesis, second one is exponentiation. Exponentiation is nothing but this power is also known as exponentiation, okay? And the same power, or you can call it exponentiation as well. So first is the parenthesis, second is exponentiation, then we have multiplication, division, addition, and then subtraction. Addition and subtraction have same precedence, so you can just switch them as well. Okay, any question in this?
No, ma'am.
All right, so let's just create some values and we'll test all of these. Okay, so let's say a is equal to 40, b is equal to 10, and I wanted to do addition, so I'm going to say add is equal to a plus b, subtract is equal to a minus b multiply is equal to a multiply by b. Division is equal to a divided by b. Then we want floor division, so I have— floor division is equal to a floor division b. When you wanted to know remainder, so I'm writing remain— a modulo b. Then the next one is to the power, so is equal to a to the power of b. Any other which is left? I think we have covered. Okay, so now let's print all of them. Addition is add. I'm going to use Same statement. Subtraction is sub. Then this is for multiplication. Then the next one is the division. Then we have— a to the power of b. Now you can see when we are going to add, 40 plus 10 is equal to 50. 40 minus 10 is 30. Then we have multiplication, division, which is in float value, floor division, which is the single value in the integer format, which is the first operand. Remainder is 0 because 40 is totally divisible by 10, and a to the power of b is this. Any question? Yeah, any question?
No, ma'am.
So this is arithmetic operator. Now the next set of operator is called comparison operator that will help you com— compare multiple values. Just like in normal mathematics, we have greater than, less than, equal to, not equal to. Same way in Python also, you have to use certain operators for that. So if you wanted to write equal to somewhere, then you have to follow this. Let me just— comparison operator. First one is less than, then equal to, greater than, equal to. If you wanted to write equal to, you have to write it 2 times, like equal to symbol should be 2 times. If you wanted to write not equal to, then this is the correct symbol to write it. Any question in this? This one is for not equal. This is something to remember, so make a note of it. That exclamation mark and equal to means not equal. Every time when you are using the comparison operator, they will result in true and false. Okay, every results will be true and false. If I'm going to say print a == b, then it's going to give false because both values are not same. If I'm going to say print a b, then true because 40 is greater than 10. Same way, if I am writing a != b, then this time it will give you true because the both values are not equal. So this is how your comparison operator you have to use. Comparison operators just for the comparison, and results will be in the true and false. Whenever the results are in the true and false, these type of a data we call it Boolean data. Which data? In short, whenever you are going to test the data type, like which type of a data you are getting, then you will get it bool. Like, in short, it will be printed as bool. Okay, so this is Boolean data type. Then comes the next one, which is the logical operator. Logical operator means when you wanted to compare two values, two conditions, then you have to use the logical operator. There are 3 logical operators. First is the AND, second is OR, third one is NOT. When it comes to AND, AND will give you true only when both of the conditions are true. OR will work only if one of the conditions out of the 2 conditions is true, then only OR will give you true. NOT means opposite of what you have. AND, OR, and NOT, opposite of the value. Okay, if it is true, it will result as false. If it is false, then it will result as true. So OR is when you have 2 conditions and one of them is true, then the result will be true. In AND case, when you have 2 conditions and both of them are true, then only it will return true. Any question? Yeah, any question in this? So suppose I'm writing the AND operator between two conditions. My first condition is a is greater than b, and then I'm writing a is not equal to b. If both of the conditions are true, then only it will return true. So 40 is greater than 10, which is true. 40 is not equal to 10, again it's true. If I'm going to write down the same conditions with the AND operator itself, but this time instead of writing not equal to, I'm writing equal to, then you can see that I'm getting false. Because AND operator says it will give you true only if when both of the conditions are true. This is condition second and this is condition one. So when both of the conditions are true, then only it will return true, otherwise it will return false. If I'm going to write down the same thing, but in this time I'm going to change the AND operator to OR operator, then at the time you will get true because one of the condition is true. That is why you are getting true as in the result. Any question?
No, ma'am.
Not is whatever you have. You will get the opposite of it. So suppose I am going to write c is equal to true. Simply I am storing one value which is true, which is a Boolean value. And now I am going to say print not c. Now you can see I have stored true, but in the results I am getting false. So this is what not logic operator is. Now the next is assignment operator, just like when we assign some values, right? So let's say we have two variables already created above. One is a and then second one is b. So a and b we have already defined. When you wanted to redefine it, let's say I wanted to update the value, whatever is existingly there, I wanted to add something in that value. So one way is I can say a is equal to a plus 2. Let's say, yeah, 2. Now if I will do print a, I will get 42 because earlier I have stored 40 and now I have 2 added in it, which is 42. But in short, you can write down the same thing with the assignment operator as well. So when you wanted to add something in the already existing variable, then you have to write it a plus equal to 2. Now if I'm going to rerun this one cell, it will give me 44. Now you can see instead of writing the a variable 2 times, I'm writing it single time only because I'm using the assignment operator. So assignment operator helps you to assign values to the variable. Earlier we have used only single equal to, like when I have written a 40, it means that was single equal to assignment operator. And now I am using and, add operator. You can also do the subtraction the same way or multiplication the same way. If I'm going— if I wanted to subtract it, I simply have to remove this addition symbol with this subtraction, and I have subtracted 2. Now the output should be 42. Now I'm going to rerun this. Now you can see the output is 42. When you wanted to do multiplication, division, or you wanted to go with the modulo or anything, you can use the same arithmetical operator with the assignment as well. So let's say I wanted to do floor division, so I have to write it like this: a floor division with 2, and then save it back in the variable a. Now I will just run this, and the answer is 21 because we are dividing 42 by 2 and whatever the value comes up is in 21. 42 is totally divisible by 2, that is why you are getting it like this. When you wanted to— let's say now I'm going to add 1. Okay, now let's, let's skip it. We already have 21. Now if I am going to perform the same thing, then it's going to give me 10 because we have certain remainders as well. When you wanted to know the remainder, then you can use that modulo concept over here. Again, any question in this? Yeah, anyone, any question? So these are simply the operators which will help you perform things. Like whenever, uh, programmers or coders start learning, they start with Hello World and then they create a calculator. So after learning these concepts, you can create a calculator. There is one more concept which is required in calculator, which is the conditional statements. Okay, so now the next operator that we have is the identity operator. Identity operator is used just to identify which— try which— like whether the value exists or whether the values are same or not. So there are two identity operators: is and is not. Our identity operator, they help you check if two values are located on the same part of the memory or not. 2 variables that are equal cannot be identical. Let's take an example. If I'm writing— let's see, I'm writing 3 variables we already have, right? A, B, and C. Okay, so let's say A is equal to— I'm just redefining it with 50. B is equal to 10. Let's say c is equal to a and d is equal to b. I have created 4 variables. Now this time my variable c is having the same value which is 50, my variable d is having the same value which is 10. Now I am going to check whether they are identical or not. Print a is c, it's giving true because the same value we have. If I'm going to say if a is b, false. It means basically it is checking whether it has the same value or not. Or else I can write it is d, that too will be false because we have stored the same value in the variable c, and for variable c if we are going to check, it will return true. Otherwise For other condition, it's going to return as false. You can also write it like a is not d, which is true. a is not c, this is false. So these two are the identity operator. Just like we have identity operator to check, uh, the identity, whether they are identical or not, same way we have membership operator. Membership operator helps you test whether value which you are trying to test is in the variable or not. So simply, this works with the, let's say, list. List is equal to list2 is equal to square bracket 10, 20, 30, 40, 50. Okay, and now I have stored already a and b, I have the variables, and I'm going to check whether a exist in c or not? A in list2, it's saying true because 50 we have. Now let's say I'm going to update the variable value, which is instead of 50 I'm going to write 80. Okay, and then I will just run it. Now you can see 50— 80 I have written. So 80 is not in the list2, that is why you are getting False. So this membership operator means— membership operators, membership operators means when you wanted to check whether that value exists or not. When it comes to whether it exists or not, then you have to use not in. So a not in list2. B, let's say, B not in list 2. So now it again says false. So these are the membership operator because it checks whether that value exists or not. Any question in this? Yeah, anyone? No, ma'am. Is this clear to everyone?
Yes.
Same way, like, other operators are also there, but for those, like, we need not to discuss is because we have to combine all these basic operators and then You can do anything. Like if I'm going to combine, like for a condition, I'm going to write down 4 conditions, then for 4 conditions obviously I need a mathematical operator also. For that I need a comparison operator also, or maybe I need the one which is identity operator— no, not identity operator, logic— yeah, logical operator. So AND, OR, NOT I can use. I can use comparison operator, and obviously I have to use the mathematical operator. It means This time I'm combining multiple operators. Okay, now for creating— let's talk about creating a calculator. Can anyone tell me how calculator works? Just a simple definition. If I ask you about calculator, then what is the calculator and how many types of calculator you have seen exactly? Yes, anyone? How many types of calculator you have seen? No one wants to try? Or no one have used calculator?
Like basic calculators only. Like, uh, if we enter two values, like number 1, number 2, then you enter the operation. You will, like, for example, addition means addition, some value, or subtraction means subtraction, multiplication, division. Like output we can Basic.
Yeah, so there are multiple types of calculator that you can create, okay? But for creating calculator, we need to learn how to work with the multiple conditions, okay? So after learning that concept of conditional statement, then we will start building the calculator. But I'm just giving you an information that you have to basically select one type of calculator. So there are different types of calculator based on your need. You have to create it. Let's say if I'm going with the basic calculator. So basic calculator is used by, let's say, in college we use, in school we use, where we have to do some simple mathematical operation like addition, subtraction, multiplication, division, and so on. Just like you can say everyday calculation you wanted to do. Second type of calculator we have is the scientific calculator. You can also create a scientific calculator. Those who have the deep understanding of mathematics like going with sine, cos, tan, log, or anything related to factorials, that too can be calculated. Only it— that only that matters is the logic. Okay, so if you are creating the basic calculator, it means you have the basic understanding of the concepts. If you are going with the scientific calculator, it means you have the understanding of the logic. So it's not about the maths, it's about the logic, that how good your logic is, whether you are able to write it in terms of Python or not. Then we have other type of calculators also. Suppose any one of you have the knowledge about finance, so maybe someone is taking loan of, let's say, 10 lakhs, then he's going to repay it in 10 years, then what will be the interest rate and also how much EMI that person has to pay? So that is basically a finance calculator you can create, or you can say loan interest rate calculator. Or if suppose someone is starting going to start invest in stocks, and on an average, like, like the person is starting with SIP. So that SIP means it's going to get the, the, like, most probably, like, there is an average hike, like you can say, or average increment, right, that you can expect. So you can create those type of calculator as well. That if you are making an SIP of ₹15,000 per month and the hike is, let's say, 14% per year, then obviously by the end of first year you will get this and you will have this much amount. And if you are going to reinvest it— and basically it totally depends upon your interest. Let's say those who are interested in finance can create a finance calculator, but those who are interested specifically in programming can create a programming calculator as well. In terms of programming, you can create— let's say you, if you have like in college, if you have taken the computer science stream or anything related to engineering stream, like maybe electronics, electrical, digital, any stream basically. So you might have heard about the number system, like converting binary numbers to octal numbers or binary numbers to decimal numbers or hexadecimal number or bitwise calculation. All these can be done using programming calculator. So you can write your own logic to create a programming calculator as well. So depending upon your interest and your understanding, you have to choose one calculator that we will start— that you have to basically start creating after tomorrow's session, because in tomorrow's session we will be covering the conditional statement. Okay, so you have to first create a basic version of it. Once we will cover the concept of loops, then you have to add more advancements in that project. Any question, anyone, in this? No, ma'am. Is this clear to everyone?
Yes. Yes, ma'am.
Okay, so, so far whatever we have covered in the sessions, those who are requesting for the notes, I have added it on my GitHub. Okay, I will share the link on Discord channel so you can get— I will update it, uh, like maybe weekly. Okay, so I will share that link also in the Discord, and I'm sharing same in the chat. Okay. You can use this link for the notes. Now, if anyone have any question related to anything, you can let me know.
Is there any kind of project related to data analyst in this course?
So related to data analyst specifically, we are not going to cover the project because we have only 15 days for Python, and 15 days we are going to cover the basics and the logical concept. And we will cover the file handling, exceptional handling. We will cover the modules, libraries, and basics of groups, not the projects of data analysis. Okay, okay, okay. So we have covered every operator up till now. So if I ask you a question that what is the difference between division and floor division? That what you have understood from the division and floor division?
Floor division gives you the remainder.
Okay.
And, uh, division gives you the quotient.
Floor divisions gives you an integer value. That is a part of the question, that is the first operand. Okay, when you want the remainder, you have to go with the modulo operator, or we call it modulus.
Okay, yeah, sorry.
Yeah, what is the difference between This and this, what is the difference between these two? Star or asterisk operator? One asterisk is used for multiplication and the double, double asterisk for power. Correct. Okay, so your today's task is to practice the operators along with the variables, and you have to try combining multiple operators. So by tomorrow 10 AM, I will drop some questions on Discord channel for you to practice, okay, related to the concepts that we have covered up till today's session. So I will drop some questions. You have to try to answer those questions. Okay. All right guys, so we'll connect in the next session. Bye-bye, till then.










