Conditional Statements in Python

In programming, we often want to check a conditional statement and then do something if the condition is met and do something else if the condition is not met. This is done using the If conditions.

There are two general forms of decision making structures found in most of the programming languages:

if statement

An if statement consists of a Boolean expression followed by one or more statements.

    if(BooleanExpression) :
        statement
    if(BooleanExpression) :
        statement1
        statement2
         ...

If the BoolenExpression is true, then the statements will be executed. Note that for the statement to be a part of the If condition, it must be indented by 4 spaces.

if...else statement

An if statement can be followed by an optional else statement, which executes when the Boolean expression is false.

This content is for paid members only.

Join our membership for lifelong unlimited access to all our data science learning content and resources.

Related Downloads