The document discusses comparison and logical operators in Python. It provides examples of using comparison operators like ==, !=, >, <, >=, <= and logical operators like and, or. Comparison operators check for equality or inequality between values, while logical operators combine conditional statements. Examples show how comparison operators return True or False based on the values being compared and how logical operators return True if either or both conditional statements are True, depending on if the operator is 'and' or 'or'. The document encourages practicing with different values to understand how the operators work.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
66 views
Comparison and Logical Operators
The document discusses comparison and logical operators in Python. It provides examples of using comparison operators like ==, !=, >, <, >=, <= and logical operators like and, or. Comparison operators check for equality or inequality between values, while logical operators combine conditional statements. Examples show how comparison operators return True or False based on the values being compared and how logical operators return True if either or both conditional statements are True, depending on if the operator is 'and' or 'or'. The document encourages practicing with different values to understand how the operators work.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3
Hi everyone, Today we will be covering a comparison operator, the
logical operator the way we use them in jupyter notebook. So we have
several operators in python comparison operators, logical operators let see how we can use them. You may be already aware of it but let me show couples of them and you can try others, other operators at home. So it's false we have already discussed it. Let's try this one this is true, greater than equal to. It is a true statement let's try this one this is true, less than equal to. These are the operators see when you are dealing with the small mathematical things you may have to use them check you the difference between two items or probably the bigger once that is where you can use them so this is less than or equal to, the one that is used so its not equal to but it is definitely 1 is definitely less than 4 so that is the reason it is showing true ok will try that in your system you will see it works correctly. Let's try other once equality it is true. let's try this I don't think I need to explain it when you are using 1 == 2 if one is equal to the item which is on the right side. So if I will do this what would happen, nothing since we are using logical operators, comparison operators, false this is correct. Let's try this, false can anybody tell me why it is false? well, it's in the codes cannot be equal to one it is not Afcos what if I remove these quotes it will be the same as true. The moment I will add these quotes it's not a number anymore, is it? no, it's not. Numbers are treated differently, Strings are treated differently, List is managed in a different way so on so for. Inequality let's check this out, remember these operators or don't remember them if you keep using them regularly it will be fed in your system. So this is the Inequality sign basically not equal to you can say that not equal to this is equal to, this is not equal to, yes 1 is not equal to 2 that is correct this is the reason you are true as in result these are the comparison operator. Let's check out logical operators this is the interesting part when you are trying to compare use logical operators you will find it interesting the good is you can use other numbers, other data it not take your much time just check your knowledge and enhance your knowledge this part I really like this part and guys since we are doing it we should be good at statistics so I would suggest you all this is a sort of pr-represent start going through basic statistics as a mean, median, mode so what is the difference, recommendations, combinations whatever you understand they are easy to understand there is no rocket science in it, Question you can always ask but if you can prepare yourself that will be a great help while you are learning. So moving on with the logical operators so we are using and here remember and did you see the result so I am using the and operator here, and logical operator so both these items should meet the criteria if one of them is following apart then the answer will be false. let me change this let's see if there is the change in result do you see it has changed into true so what is and function doing here? and logical operator doing here it is doing a logical, logical it is running and operation in the first item which is this and in the second item both of these are correct then result will be true. Unlike the original one that we used let's see false, now it is false I guess it's simple or Let's use this one earlier we used and now let's use or true why it's showing true? because this is the same information that we added here because or would mean one of them has to be correct and one of them is correct this is the reason we have true here and the and function both of these operations we have trying to perform has to be correct which was not the case trying using other numbers and you will understand it shouldn't take much time. Let's try multiple logical operators here true, I think this explains itself 1==2 it's incorrect it has to be false then 2 == 3 which is again incorrect but the third one is correct and we have used or logical operators this is the reason the output we have got it's in the form of true bullion remember the bullion true or false that is how we are getting output here try the numbers see how you can play off with the data. Let's try this I, these are the statements that you would use a lot of times if-else and else statement they are not tuff to understand but you may have to use it to you know, apply certain logic and understand. Before I moved on to else statement I would think that comparison and logical operators are clear just try using this operator at home, apply whatever you can do several operators there, try to compare the numbers, apply logical operators and see the kind of results that you would get they are easy to understand but you have to put in your effort to make sure that you have understood completely because on and off you may have to use it but you won't to anywhere in a situation wherein you tend to forget. These are the basic ones so I would expect all of you to absolutely mindful and guys once you will be do it I don't think the chance of forgetting it. So keep it up I will explain about the if-else statements in other videos. Today for this video that's it. Thank you