Comparison, Logical, and Membership Operators

In this lesson, we will be talking about built-in Python operators that will give us a Boolean result.

Comparison Operators

Comparison operators help us compare the left and the right operand in terms of magnitude.

Symbols:
    == Equal to
    != Not Equal to
    > Greater than
    < Less than
    >= Greater than or Equal to
    <= Less than or Equal to
# Comparison Examples

num1 = 42
num2 = 6

print('num1 == num2:', num1 == num2)
print('num1 != num2:', num1 != num2)
print('num1 > num2:', num1 > num2)
print('num1 < num2:', num1 < num2)
print('num1 >= num2:', num1 >= num2)
print('num1 <= num2:', num1 <= num2)

Logical Operators

We use logical operators to combine boolean expressions.

The most basic boolean expressions possible are True and False.

Membership Operators

Membership operation allow us to check for the exitence of data from an iterable data type.

We will look at some examples with Strings and Lists.

Order of Precedence/Operations in Python 3

During assignment or boolean expression evaluation, the order of calculation follows:

Last updated