- Podcasts
- Python To You
- _11 Python Tutorial for Beginners _ Operators in Python
_11 Python Tutorial for Beginners _ Operators in Python
Python To You
- October 14, 2026
- 11 min
About this episode
No description.
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
_11 Python Tutorial for Beginners _ Operators in Python
My name is Daivin Reddy and let's continue with the series on Python. So till this point we have covered a lot of stuff, right? We know how to work with IDLE now. We know how to perform some of the operations and in this video we'll try to work with operators. Now one of some of the operators we have used, right? We have worked with arithmetic operators, which is.
So we'll talk about arithmetic operators, assignment operators, relational operators, and logical operators. And we have one more which is unary operator. So let's start with arithmetic. In fact, we have seen arithmetic, right? We have worked with addition subtraction. They are very simple, right? So in fact, we have done that before. So I'll be using some variables here. Let's say x equal to 2 and y is equal to 3. So we got two variables and I want to perform certain operations. And we can do that, right? We have done that before. So you can say X plus Y, you can say X minus Y, X multiply by Y. I guess I just pressed 4 by mistake. And then when you say X divided by Y, even that works.
Else what if i say i can add two numbers like x equal to x plus 2 so what i'm doing here is i'm adding the value x itself with 2 so which means if my x value is let's say 2 plus 2 which is 4 right that's what I get that's what I'm expecting here so if I say x we got 4 now the same operation you can do in a shortcut way you know we love shortcuts so here also we have some shortcuts which is if you want to do the same thing you can say x I want to increment okay what is increment enhancing the values So you will say x plus. I want to increment myself with 2. So you can say x plus equal to 2. So you are incrementing yourself by 2. And now if I say x, you can see we got the value which is 6. So x was 4 initially. And then I'm incrementing by 2 again. So we got 6. So instead of saying x equal to x plus 2, we can say x plus equal to 2.
Multiply equal to 3 so what we're doing is we are multiplying x by itself so x is 6 now and when you say 6 into 3 we got 18. uh is that yes that's right okay so this thing is working you can do shorthand as well you can try division and subtraction by yourself can we do assignment like this let's say we have two variables here a and b i want to assign value let's say 5 and 6 to a and b So we can write in two lines, right? We can say A equal to 5 and B equal to 6 or you can do that in one line. You can say A comma B is equal to 5 comma 6. So you can do assignment in one line itself. So if I say enter, there is no error. If I try to fetch the value of A, which is 5, if you want to try to fetch the value of B.
Now we can also use, so now we can negate it with the help of minus n. So when you say minus n, so if I say the value of n, it's still 7, right? So what you can do is if you want to assign the negative value, you can say n is equal to minus n. And if I say enter, and if I print the value of n now, which is minus 7. So you can, you know, put a negative sign just by giving a unit operator which is minus. So that's your arithmetic operators assignment and unity. The next two operators which we have is or two kind of operators which we have is logical operators and relational operators. Let's start with relational first. Now what is relational? Now in fact we have done one of the thing before right in one of the video. Where we can compare two numbers or we can compare two stuff.
I want to check if A is less than B. So you can say A is less than B. And the answer is yes, right? Because A is 5 and B is 6. So when I say enter now, it says true. And if you remember, we have done that in Boolean. So it returns a true and false. So when you use this angular symbol, it's less than. We can also use greater than symbol.
So how do you check for this comparison if they are same? Because we cannot use single equal to because single equal to means you are assigning it. We are not assigning here. We are comparing it. So in that case, you'll be using double equal to. And then you will say B and you can see we got false.
And B is 6 so of course it will give you false now in that case what you will do is you will say let's change the value of A I will say A is also 6 so now B is 6 A is 6 let's perform the same operation I will say A is equal to B and you can see we got true now they are same right so it will give you true i want to check if a is less than or equal to b can we do both at the same time less than and equal to yes we can so we can say a less than equal to b so we can use this symbol in fact in maths we also have a symbol right so the same way we have in programming we can just put less than and equal to the same thing can be done for greater than equal to Of course, it's not greater or less.
So these are called as relational because you are trying to relate to different values. The next set we have is logical operators. So before understanding what logical operators are, you need to understand the concept of true and false and relation between. So if you have two conditions and if you want to combine those two conditions, now it can be based on and or it can be based on or or it can be not.
Now let's say we have two conditions one related to a we can say if a let's just clean this shell once so let's again start with variables we can say here we got two variables we'll say a is equal to five and b is equal to let's say four we got two variables okay and individually I want to check their preference example if a. is less than 8 and I also want to check b should not be greater than 5 how do I check both and I want to make sure that a should be less than 8 and b should be less than 5 in that case you need to you will write two conditions one is a less than 8 and b is less than 5 so we have two conditions here what should I put in between so in that case you can use our logical operators which is and so I want to compare I want to check both right so I will say and and you can see we got true because both are true now what if I say I want to check if a is less than eight and b is less than two.
Because to understand that, we have a table here. Now, this table is also called a true table. You can represent true with 1 and false with 0. This is how it looks like. So, when you have, let's say we have x and y. So, x represents one conditional output and y represents second conditional output.
If x is 0 and y is 1, in that case, you will get again false. So you have to make sure both are true. Then only you will get true. And you can see the last one now. So when you have the last row where you have 1 and 1, then you will get 1. So if both the conditionals are true, then only you will get true. That's the property of and false. Now the same thing can be done for OR.
Now this is how your OR truth table looks like. Now in OR what we have is, so we have the same table. If you get at least one condition true, the resultant condition will also be true, right? So in this case, if I do the same thing but not with AND, with OR, you can see the first condition is true, second is false.
That's how your and and all works we can also use a not here now it is not not basically reverses your output example let's say if i say x is equal to true because that's a resultant thing right okay my bad so if i say x is equal to true so we got a true value right and if i print x you've got true but if i want to negate it what i will do is i will use not x in that case you will say you got false Right.
So the value of X is false. Initially, the value of X was true. Now you are making it false. So that's how you can use not. Now, this is a logical operation. OK, so when you have conditions and if you want to compare two conditions, that's where we use logical operators and or or not. Again, you'll be using this a lot in the further videos when we talk about, you know, different look patterns. We want to print something and then we'll do some amazing stuff. In that amazing stuff, we'll be using all these things. Just a reminder, whatever we are doing now is just a foundation for you so that you can work on complex codes, right?
