Fall 2024 - P3
3.6.3 Simple Python Conditionals
Python Conditionals:
if
statement:
This checks a condition. If the condition evaluates to True
, the code block under the if
statement is executed.
elif
statement:
This is short for “else if” in Python. It allows you to check multiple conditions after the if
statement. If the first condition is False
, but this one is True
, it runs.
else
statement:
If none of the previous conditions are True
, the code under else
is executed.
Example of Python Conditionals:
age = 18
if age < 18:
print("You are a minor.")
elif age == 18:
print("You just became an adult!")
else:
print("You are an adult.")