Key Concepts

Review core concepts you need to learn to master this subject

Equal Operator ==

# Equal operator if 'Yes' == 'Yes': # evaluates to True print('They are equal') if (2 > 1) == (5 < 10): # evaluates to True print('Both expressions give the same result') c = '2' d = 2 if c == d: print('They are equal') else: print('They are not equal')

The equal operator, ==, is used to compare two values, variables or expressions to determine if they are the same.

If the values being compared are the same, the operator returns True, otherwise it returns False.

The operator takes the data type into account when making the comparison, so a string value of "2" is not considered the same as a numeric value of 2.

Control Flow
Lesson 1 of 2
  1. 1
    Imagine waking up in the morning. You wake up and think, “Ugh. Is it a weekday?” If so, you have to get up and get dressed and get ready for work or school. If not, you can sleep in a bit longer…
  2. 2
    In order to build control flow into our program, we want to be able to check if something is true or not. A boolean expression is a statement that can either be True or False. Let’s go back to the…
  3. 3
    Now that we understand what boolean expressions are, let’s learn to create them in Python. We can create a boolean expression by using relational operators. Relational operators compare two it…
  4. 4
    Before we go any further, let’s talk a little bit about True and False. You may notice that when you type them in the code editor (with uppercase T and F), they appear in a different color than var…
  5. 5
    “Okay okay okay, boolean variables, boolean expressions, blah blah blah, I thought I was learning how to build control flow into my code!” You are, I promise you! Understanding boolean variables…
  6. 6
    Now that we’ve added conditional statements to our toolkit for building control flow, let’s explore more ways to create boolean expressions. So far we know two relational operators, equals and not …
  7. 7
    Often, the conditions you want to check in your conditional statement will require more than one boolean expression to cover. In these cases, you can build larger boolean expressions using _boolean…
  8. 8
    The boolean operator or combines two expressions into a larger expression that is True if either component is True. Consider the statement Oranges are a fruit or apples are a vegetable. This s…
  9. 9
    The final boolean operator we will cover is not. This operator is straightforward: when applied to any boolean expression it reverses the boolean value. So if we have a True statement and apply a n…
  10. 10
    As you can tell from your work with Calvin Coolidge’s Cool College, once you start including lots of if statements in a function the code becomes a little cluttered and clunky. Luckily, there are…
  11. 11
    We have if statements, we have else statements, we can also have elif statements. Now you may be asking yourself, what the heck is an elif statement? It’s exactly what it sounds like, “else if”. A…
  12. 12
    Great job! We covered a ton of material in this lesson and we’ve increased the number of tools in our Python toolkit by several-fold. Let’s review what we’ve learned this lesson: - Boolean express…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo