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

What Program Flows are in Python?

You will learn what program flows are in Python, and how this links to conditional statements and boolean expressions in Python.

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 as True or 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 to 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 of less-than.

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

Again the same principles apply.

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 an 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 an 8 hours FREE video course with full explanations, projects on each level, 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.
  • 2 FREE eBooks to support your Python learning.

See the full FREE course page here.

Learn Python

Learn Python A BEGINNERS GUIDE TO PYTHON

  • 70 pages to get you started on your journey to master Python.
  • How to install your setup with Anaconda.
  • Written description and introduction to all concepts.
  • Jupyter Notebooks prepared for 17 projects.

Python 101: A CRASH COURSE

  1. How to get started with this 8 hours Python 101: A CRASH COURSE.
  2. Best practices for learning Python.
  3. How to download the material to follow along and create projects.
  4. A chapter for each lesson with a descriptioncode snippets for easy reference, and links to a lesson video.

Expert Data Science Blueprint

Expert Data Science Blueprint

  • Master the Data Science Workflow for actionable data insights.
  • How to download the material to follow along and create projects.
  • A chapter to each lesson with a Description, Learning Objective, and link to the lesson video.

Machine Learning

Machine Learning – The Simple Path to Mastery

  • How to get started with Machine Learning.
  • How to download the material to follow along and make the projects.
  • One chapter for each lesson with a Description, Learning Objectives, and link to the lesson video.

4 thoughts on “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

    Reply

Leave a Comment