Equality
Learning Objective
- If two things are equal, the order we
- Python can help us distinguish if two things are equal.
Lesson
In math, we use the equals sign ('=') when we want to say two things are the same. For example the equation, 1 + 1 = 2 tells us that the left side, 1 + 1 is the same as the right side, 2.
If an equation is correct, we say that it is True. So 1 + 1 = 2 is True. But if an equation is incorrect or wrong, we say it is False. The equation 1 + 1 = 3 is False
A computer can help us solve math equations. Try this: Copy and paste the code below in your editor. What happens when you run it?
print(1 + 1 == 2)You should notice that the computer displays True. This is because the equation 1 + 1 == 2 is True.
Careful! Did you notice that when we asked the computer to check our equation, a double equal sign == was used, not a single equals sign =. When we program, to check if two things are the same, we always use two equals signs ==.
Try this
Run the code below and see what happens. Is this true or false?
pyprint(3 + 6 == 9)What if we change the order? Is this true of false?
pyprint(9 == 3 + 6)Python can help us do math. Is this equation True or False?
156 * 45 == 8020What happens if we forget to use a double equals sign?
pyprint(9 = 3 + 6)
Equality with variables
Sometimes it can be harder to tell if two things are the same. Consider the example below.
number_one = 47
number_two = 47
print(number_one == number_two)What do you think with be printed out?