Decision Making Statement in Python
Decision Making Statement in Python
Topperworld.in
• Decision making is the most important aspect of almost all the programming
languages.
• As the name implies, decision making allows us to run a particular block of
code for a particular decision.
• Here, the decisions are made on the validity of the particular conditions.
• Condition checking is the backbone of decision making.
Statement Description
❖ Indentation in Python
• For the ease of programming and to achieve simplicity, python doesn't
allow the use of parentheses for the block level code.
• In Python, indentation is used to declare a block.
©Topperworld
Python Programming
• If two statements are at the same indentation level, then they are the part
of the same block.
• Indentation is the most used part of the python language since it declares
the block of code.
• All the statements of one block are intended at the same level
indentation.
❖ if statement
• The if statement is used to test a particular condition and if the
condition is true, it executes a block of code known as if-block.
• The condition of if statement can be any valid logical expression which
can be either evaluated to true or false.
©Topperworld
Python Programming
Syntax:
1. if expression:
2. statement
Example:
Output:
©Topperworld
Python Programming
❖ if-else statement
• The if-else statement provides an else block combined with the if
statement which is executed in the false case of the condition.
• If the condition is true, then the if-block is executed. Otherwise, the else-
block is executed.
Syntax:
1. if condition:
2. #block of statements
3. else:
4. #another block of statements (else-block)
©Topperworld
Python Programming
Example:
Output:
❖ elif statement
• The elif statement enables us to check multiple conditions and execute
the specific block of statements depending upon the true condition
among them.
• We can have any number of elif statements in our program depending
upon our need. However, using elif is optional.
• The elif statement works like an if-else-if ladder statement in C. It must be
succeeded by an if statement.
©Topperworld
Python Programming
Syntax:
if expression 1:
# block of statements
1.
elif expression 2:
# block of statements
2.
elif expression 3:
# block of statements
3.
else:
# block of statements
Example:
7.
Python Programming
Output:
©Topperworld