Section Introduction
In this section of the course, we're going to dive into conditionals in a python. Now a conditional is one of the foundational concepts around what it takes to make a python program become dynamic.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

By dynamic what I mean is that your program can start making decisions which is a pretty exciting and very cool feature that pretty much every type of application is going to have to have at some level or another. Now conditionals are simply a way of saying if one situation occurs I want you as a program to perform one task but if a different situation occurs I want you to perform this other task.

Let's take a little bit of a real-world example with this. So let's say that we're building out an authentication system which simply means we want to check to see if a user who goes to our website or our mobile application is allowed to go into the system. We could build something like this and this isn't the syntax. This is more of a visual so we can say if user, and then password are correct so we'll say correct.

large

Then I want to perform a couple of tasks so if the answer is yes then I want to come down here and say let into site.

large

But now what if it's not correct? We may have a couple of different options. So if it's no then we don't want to only say they're not allowed into the site. So that's definitely part of it we're not going to let someone who's not authorized in but we may do is have a secondary check and a secondary conditional. So we say if that's not correct then no we're not going to let them into the site. So not authorized but then we may also want to perform some other checks to say something like Okay if the email they entered or the user name they entered didn't even exist in the system. Maybe we want to check and say "Would you like to register?"

large

Then we could have different conditionals at different levels. And I like to think of conditionals as these trees structures where you can have all of these different scenarios and these different actions and one thing that's beautiful about conditionals you only have to think of your conditions as having a yes or a no type answer. So if that condition is met it's a yes. If the condition is not met it's a no. And then you also have the ability to branch off and give secondary conditions to make your systems even more specialized. So now that you have a good idea of what a conditional is let's dive into the actual syntax so that we can start building into our Python programs.