
Everything we've done so far has been pretty limited,

that we had to do the same thing on all data.

We couldn't do anything that really depended on what the data was.

What we're going to do next is figure out a way to make code behave differently

based on decisions.

The first thing we're going to do is figure out some ways to make comparisons,

so we have a way to test and decide what we should do.

Python provides lots of different operators for doing comparisons.

There are things similar to what we've used in math.

We have a less than sign that compares 2 numbers.

We have the greater than.

We have a less than or equal to. Things like this...

All of these operate on numbers, so we can have a number followed by

a comparison operator, followed by another number.

This is very similar to the grammar we saw earlier for arithmetic expressions,

but now instead of having a plus or times here,

we can have something that does a comparison.

The output of a comparison though is not a number.

It's a Boolean value, and a Boolean value is 1 of 2 things.

It's either the value True or the value False.

Let's see some examples in the Python interpreter.

First, we'll use the less than to compare 2 and 3.

So 2 is less than 3, so we expect the result to be true.

When we run this, we see that the result is true.

If we compare a number greater than 3, let's say 21 < 3.

The result will be false.

We can have any expression we want with a comparison,

so we can do 7 * 3 < 21.

When we run that, we also get false because 7 x 3 = 21,

which is not less than 21.

Another comparison operator we can use is not equal to.

So != means not equal to.

So 7 * 3 != 21 is false because 7 x 3 is equal to 21.

If we want to do equality comparison, we don't use the equal sign,

we use 2 equal signs.

We call that the double equal.

So now we have 7 * 3 == 21, and the result there is true.

Now we're going to have a quiz to see if you can figure out why we need to use

the == here instead of just the single =.

The question is, why is the equality comparison done using ==,

having 2 equals, instead of just a single = sign?

The possible answers: Because = means approximately equal,

and we want to do exact equality comparisons.

Because we needed to use 2 characters for the not equal comparison,

and we wanted the equal to be the same length.

Because Guido, the designer of Python, really likes = signs.

Because the single = sign means assignment,

or it doesn't really matter. We can use either == or =.