Python tutorial- comparison and logical operators


Comparison and Logical operators

Comparison operators:


Comparison operators are used to compare different values. The table below is the summary of comparison operators that can be used in Python.

Symbol Expression Description
== x==y x equals y
x>y x is greater than y
>= x>=y x is greater than or equal to y
x<y x is less than y
<= x<=y x is less than or equal to y
!= x!=y x doesn’t equal to y
is x is y x and y are the same object
is not x is not y x and y are not the same object
in x in y x is a member of y
not in x not in y x is not a member of y

Logical Operators:


Logical operators (and, or) are used to work with True or False values. These operators are import when you want to evaluate more than one condition.

Operand Operator Operand Result
False and False False
False and True False
True and False False
True and True True
False or False False
False or True True
True or False True
True or True True



Comments




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.