Program Flows in Python – Conditional Statements and Boolean Expressions Controls the Program Flow

What will we cover?

We will cover what a program flow is, how this links to conditional statements and boolean expressions.

Step 1: Let’s recall what boolean expressions are

Boolean expression is the building block of conditional statements. So let’s make a brief recap of it.

Given two variables a and b, we have the following boolean expressions with them.

  • Equals: a == b
  • Not Equals: a != b
  • Less than: a < b
  • Less than or equal to: a <= b
  • Greater than: a > b
  • Greater than or equal to: a >= b

Where depending on the values in a and b the expressions will evaluate to True of False.

Step 2: Conditional statements

Let’s demonstrate a few if-statements here.

Equality between variables.

a = 10
b = 10
if a == b:
    print("a equals b")

Notice, that if a was not equal b, then it would not print the statement. That is, the indented code after the if-statement, is only executed if the boolean expression evaluates to True.

Another example with less-than.

a = 10
b = 8
if a < b:
    print("a is less than b")

Again the same principles applies.

You can also have an else-clause.

a = 12
b = 12
if a > b:
    print("a is greater than b")
else:
    print("a is not greater than b")

And a elif-clause.

a = 13
b = 12
if a > b:
    print("a is greater than b")
elif a == b:
    print("a is equal to b")
else:
    print("a is less than b")

And a not-equal statement.

a = 10
b = 10
if a != b:
    print("a does not equal b")

What next?

If this is something you like and you want to get started with Python, then this is part of a 8 hours FREE video course with full explanations, projects on each levels, and guided solutions.

The course is structured with the following resources to improve your learning experience.

  • 17 video lessons teaching you everything you need to know to get started with Python.
  • 34 Jupyter Notebooks with lesson code and projects.
  • A FREE 70+ pages eBook with all the learnings from the lessons.

See the full FREE course page here.

Python Like a Pro?

If you’re serious about learning Python, there’s nothing better than strong commits. At your request, we have created an improved version of this popular free online course.

This version has the following benefits to enhance your learning journey.

  1.  Tracking your progress in the course.
  2.  Questionaries to ensure you understand concepts between important lessons.
  3. Downloadable Cheat Sheets for fast lookup what you learned.
  4. Direct Q&A with the instructor to help you to understand the material better.
  5. Added material for better explanations and insider knowledge.
  6. Extra videos with more explanations and stories.
  7.  Certificate at completion.

Start the change in your life and commit to doing something amazing that you have always dreamed of.

Sign up and become part of the exclusive Python Like a Pro elite.

4 Replies to “Program Flows in Python – Conditional Statements and Boolean Expressions Controls the Program Flow”

  1. i got this message “Your submission failed. The server responded with (code ). Please contact the developer of this form processor to improve this message. Learn More” when i subscribe to get free ebook, sir! would you please fix it, please! or tell me the link to get it the free ebook of Learn Python via email me at ksiayahibuku2@gmail.com

Leave a Reply

%d bloggers like this: