Learn Python Episode #21: If, Elif, Else Statements

Get The Learn to Code Course Bundle!

Enroll in The Complete Python Course on Udemy!

In this tutorial we are going to be learning about the conditional statements available to you in Python. So, we’re going to be learning about the if-else statement, and this is basically provides us a way to evaluate if something is true or false, and then perform something whether or not the condition is met. Let’s write an if-else statement.

check = True

if check == False:
print("It is false")
print("It is actually equal to True")

This is going to print out “It is actually equal to True” in the console. First, Python is going to check if the variable is equal to false. Else, it’s going to continue through the script and print, or perform, whatever we tell it to do. This is great if we only have two conditions, but what if we want to use more than two? Between the if and else we can use an elif statement, and here we can supply an additional condition.

check = Hamburger

if check == False:
print(“It is false”)
elif check == “Hamburger”:
print(“Yummm, hamburgers”)
print(“It is actually equal to True”)

When we run this script it’s going check to see if the first condition is true, if not it will check the next condition, if not it will print the else statement. So, that’s what an if-statement is, and these are necessary for the project we are about to begin working on.

Web – https://josephdelgadillo.com/
Subscribe – https://goo.gl/tkaGgy
Follow for Updates – https://steemit.com/@jo3potato

Leave a Reply

Your email address will not be published. Required fields are marked *