Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/01-Python Comparison Operators/01-Comparison Operators.ipynb
Views: 648
Comparison Operators
In this lecture we will be learning about Comparison Operators in Python. These operators will allow us to compare variables and output a Boolean value (True or False).
If you have any sort of background in Math, these operators should be very straight forward.
First we'll present a table of the comparison operators and then work through some examples:
Table of Comparison Operators
In the table below, a=3 and b=4.
Operator | Description | Example |
---|---|---|
== | If the values of two operands are equal, then the condition becomes true. | (a == b) is not true. |
!= | If values of two operands are not equal, then condition becomes true. | (a != b) is true |
> | If the value of left operand is greater than the value of right operand, then condition becomes true. | (a > b) is not true. |
< | If the value of left operand is less than the value of right operand, then condition becomes true. | (a < b) is true. |
>= | If the value of left operand is greater than or equal to the value of right operand, then condition becomes true. | (a >= b) is not true. |
<= | If the value of left operand is less than or equal to the value of right operand, then condition becomes true. | (a <= b) is true. |
Let's now work through quick examples of each of these.
Equal
Note that ==
is a comparison operator, while =
is an assignment operator.
Not Equal
Greater Than
Less Than
Greater Than or Equal to
Less than or Equal to
Great! Go over each comparison operator to make sure you understand what each one is saying. But hopefully this was straightforward for you.
Next we will cover chained comparison operators