Python Day #3: Managing Flow with Conditional Statements
Learn how to control your programs behavior by making decisions with conditions and conditional statements.
I began this series a few articles ago to give all my readers a fair chance at learning Python the right way, following a proven roadmap that I’ve structured and taught for over the last four years.
In our last article we covered the second phase in the Python Roadmap to Success, it covered working with built-in Python functions.
In this lesson, we are going to cover managing flow in code. We are going to look at how computers think, how we can control our programs behavior and how we can use conditional statements to allow the computer to make decisions.
Over the last 8+ years I’ve been teaching full-time around the world which has given me the opportunity to work with over 1,500+ students. The last four years I’ve been teaching Python full-time.
I’ve spent this time curating a structured learning path that ensures my students have the greatest chance of success and don’t just learn but actually master Python as well as their logical thinking and problem solving.
Every week you’ll be introduced to a new topic in Python, think of this as a mini starter course to get you going and allow you to have a structured roadmap that actually builds to create you a solid foundation in Python.
Each week, I dive deep into Python and beyond, breaking it down into bite-sized pieces. While everyone else gets just a taste, my premium readers get the whole feast! Don't miss out on the full experience – join us today!
In this article, I’m going to assume you know the basics of programming and how to work with some built-in Python functions, which I covered over the last two lessons.
Today I’ll touch briefly how computers think and how we can get the computer to make decisions by managing flow, as these will continue to be the essential building blocks of your foundations in programming.
One point I should note is, spend time digesting these when I write them, after six weeks most of my posts are automatically put behind a paywall.
If you haven’t subscribed to my premium content yet, you should definitely check it out. You unlock exclusive access to all of these articles and all the code that comes with them, so you can follow along!
Plus, you’ll get access to so much more, like monthly Python projects, in-depth weekly articles, the '3 Randoms' series, and my complete archive!
I spend a lot of my week on these articles, so if you find it valuable, consider joining premium. It really helps me keep going and lets me know you’re getting something out of my work!
👉 Thank you for allowing me to do work that I find meaningful. This is my full-time job so I hope you will support my work.
If you’re already a premium reader, thank you from the bottom of my heart! You can leave feedback and recommend topics and projects at the bottom of all my articles.
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
Computers are Dumb
Yes, you read that right. In an age where we are so technologically advanced and with A.I around every corner, how can this be true?
Well, computers become smart because of us, humans. We have given the computer a set of instructions that we have written through code that allow our computers to make decisions and complete tasks.
So if you’re looking for someone to thank for where we are with technology, you can thank humans. Really, when we boil it all down a computer only understands two things, they understand 0 and 1. This is what we call binary.
Another way to think of this is a computer understands 0 and 1, or if you translate that it becomes False
and True
, with plain English we would say, No and Yes.
Every time a program runs, it goes through continuous checks while it complete tasks, it gets to a point in the program where is gets asked a question (expression). Is the answer to this question, True
or False
?
Based on the answer the computer knows which route to take to get to the next stage of the program. Now this is a very broken down example of how computers work, but none the less this is exactly what is happening.
Conditions and Expressions
A condition is simply an expression that evaluates to either True
or False
, that’s it. Now an expression you can think of kind of like a question. Is this question True or is it False?
We use expressions in different ways in programming. We can use them as values to variables, in conditional statements which we will talk about next and we can also use them in loops, which is a topic for another day.
So I will put some simple forms of expressions for you below, as well as the different logical operators we use for these operations.
All of the above are examples of expressions and these expressions become a condition as they are either True
or False
. Read over those and look at each of the logical operators as these are what we use in Python for our expressions.
This article is just to get you understanding how expressions and conditions work as well as, what they are. As we progress in the Python Roadmap to Success we will uncover more gems and see how to put them into action.
👉 If you get value from this article, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
Turning Expressions into Statements
Okay, now that we have the basics of expressions we can turn these into statements to start managing the flow of our code and getting the computer to do what we want it to.
In Python and many other languages actually, we can do this with conditional statements. A conditional statement is kind of like a sentence, this sentence results in either a Yes or No answer, which the computer will view as, True
or False
.
We have keywords in Python we can use for this, we have if
, elif
, and else
. Basically every conditional statement must include and start with if
. The other ones are optional based on the flow you are going for.
A statement would translate in English to this: if this is True, then run this block of code. If that is not True then skip. We could write some simple code to shape this here.
That is rather simple, and a lot of times we actually want to do something if the statement is not True. This is where we could opt in to end the conditional statement with an else
clause. This would then shape our code to check the following: if this is True, then run this code. Else, otherwise, run this code instead.
So anytime the first condition is not True, the else
would then automatically run. Here is some code if we were to expand on the first statement to incorporate an else clause into our code.
Since we covered built-in functions last week, now is a good time to introduce you to a new function or should I say method. A method is just a function that needs to be linked to something else in order to work.
In the above, I am using the built-in method .lower()
. This is a function that ensures all strings are lower case. This is because we should be doing this as if I said “Josh” and “josh”, Python will see these as different.
Stop Struggling—Master Python Faster!
Most people waste months bouncing between tutorials and still feel lost. I won’t let that happen to you.
👉 I’m giving you my exact system that’s been proven and tested by over 1,500 students over the last 4+ years.
My Python Masterclass gives you a clear roadmap, hands-on practice, and expert support—so you can master Python faster and with confidence.
Here’s What You Get:
✅ 135+ step-by-step lessons that make learning easy
✅ Live Q&A & 1-on-1 coaching (limited spots!)
✅ A private community so you’re never stuck
✅ Interactive tests & study guides to keep you on track
No more wasted time. No more confusion. Just real progress.
Take your career to new heights—secure your spot today!
P.S - Save over 20% with the Code: PremiumNerd20
🎁 - Get a free one-on-one coaching session with any course!
Still hesitant?
Go through the entire course, complete all material, and attend the Q&A's, if you still feel like your struggling I'll personally work with you one-on-one until you're confident!
Great, now most conditional statements you see and write will probably follow the form I have above. You would begin with an if
statement, followed by your expression. Then you’d end it with an else
clause that would be caught and ran if the if statement was not True.
Other times we may have more branches to our conditional statement, maybe you want to make them more advanced or you have multiple things that could be True.
Here, we can use the elif
clause. This clause essentially means, “else if, this is also True” or another way to phrase it would be “also if this is True”. This is like adding more than one if
statement to a conditional statement.
Something important to note to make sure the flow of code is correct. A conditional statement must start and have if
, this is the building blocks for a statement. You can only have a single if
clause in a statement.
The ending of a statement if you so wish, can end with an else
clause. You can only have a single else
clause as well. Then tucked in between these two is where we put the elif
clauses.
Technically, you can have as many elif
statements as you want, but don’t over use these. If you have more than a couple there are better ways to optimize your code, these are ways that we can look at more in future lessons.
My Best Starter Resources
Here are the best resources I have to offer to get you started with Python no matter your background! Check these out as they’re bound to maximize your growth in the field.
Code with Josh: This is my YouTube channel where I post videos every week designed to help break things down and help you grow.
Zero to Knowing: My Python Masterclass platform designed from 8 years teaching experience and that has helped over 1,500+ students succeed with Python. (All my readers gain a special 20% discount, use code: learnpython20)
My Books: Maybe you’re looking to get a bit more advanced in Python. I’ve written 3 books to help with that, from Data Analytics, to SQL all the way to Machine Learning.
The Nerd Nook: This is where you are right now! I write here multiple times per week with the sole goal of breaking down this larger than life topic to help you excel and learn Python faster than you thought was possible.
This article will be a piece to a larger roadmap but will go behind a paywall after 6 weeks! To help support my work in teaching others consider joining as a premium reader to unlock all these articles, monthly Python projects and in-depth dives.
Wrapping Up Lesson Three
We’ve wrapped up step three on your Python journey to success — and it’s a big one. Today you learned how to control the flow of your code—basically, how to get your program to think and make decisions. That’s a huge step toward thinking like a real programmer.
Just remember: computers aren’t actually smart. They only do what you tell them to do. And now, you’re learning how to tell them exactly what to do, step by step.
Next week, we’ll dive into the concept of nesting statements as well as compounding our logical expressions—this is the next phase of your learning journey. Now go spend some time this week looking back at the last few lessons and writing your own programs to practice more!
And if you’re already a premium reader—thank you! Seriously, your support helps me keep doing what I love and sharing it with you.
Let’s keep moving forward with Day #4 next week.
Hope you all have an amazing week nerds ~ Josh (Chief Nerd Officer 🤓)
👉 If you’ve been enjoying these lessons, consider subscribing to the premium version. You’ll get full access to all my past and future articles, all the code examples, extra Python projects, and more.