Nested Conditional Statements
Learn what nested conditional state
We'll cover the following
We have already covered the if
, elif
, elseif
, and else
statements, but there are situations where we want to check for a secondary condition if the first condition is evaluated as True
. In such cases, we can define an if..else
statement inside of another if..else
statement. This is called nesting of conditional statements.
Python Syntax:
if statement:
print("outer if statement")
if nested_statement:
print("nested if statement")
else:
print("nested else statement")
else:
print("outer else statement")
Let’s again take the example of determining the student grade, but now we would be nesting conditional statements to check a secondary condition of a passing or failing grade.
Example
Get hands-on with 1400+ tech skills courses.