Python Conditional – Fork In The Road

Python Conditional is like a fork in the road.

If something is True, do this, if something is False, do that.

The main start of the python conditional world is the if statement.

Python if statements will look at a statement, evaluate if it is True or False, and then run different code depending on the outcome.

if True:
  # Do Something If True
else:
  # Do Something If False

This if statement is known as a conditional.

Let’s take a look at a python conditional code sample


Python Conditional

Data Independent - Conditional

Think of conditionals as forks in the road. If something is True, then you go one way, if something is False, then you go another way.

This helps your program run certain pieces of code at some points, and other pieces of code at other points.

Let's look at a standard if...else statement. This is known as a conditional statement.

In [1]:
x = "Sunny Day"

if x == "Sunny Day":
    print ("Mow The Lawn")
else:
    print ("Wait Till Sunny Day")
Mow The Lawn
In [3]:
y = "Rainy Day"

if y == "Sunny Day":
    print ("Mow The Lawn")
else:
    print ("Wait Till Sunny Day")
Wait Till Sunny Day

Link to code above

Check out more Python Vocabulary on our Glossary Page