Python Decision Making With Detailed Explanation

This article entitle Python Decision Making is a continuation of the previous article entitled Python Operators.

Python Decision Making is an expectation of certain conditions while the program is executing and specifying the actions taken according to the given conditions.

The decision-making conditional statements contain conditions that have been evaluated by a program once the condition is true it means that the set of statements will be executed and once the condition is false it means that the other set of conditions will be executed.

What is Decision Making in Python?

In Python, decision-making is a structure that evaluates multiple expressions that will produce a boolean value or a TRUE or FALSE as the outcome. You will need to determine which action needs to be taken and which block of statements in Python needs to be executed if the outcome will be true or otherwise false.

The following image below is the general form of a typical decision-making structure which can be found in almost all programming languages.

Python Decision Making
Python Decision Making

Single Statement Suites in Python

Once a suite of an if clause only consists of a single line it may go on through the same line as the statement header.

Example

age = 26
# One-liner if-else statement
age_group = "Minor" if age < 18 else "Adult"
print(age_group)

Output

Adult

Python Types of Decision-Making Statements

StatementDescription
if statementsThe if statement consists of a boolean expression that has been followed by single or multiple statements
if…else statementsThe if statement in Python programming can be followed by an optional else statement that can be executed once the boolean expression is FALSE.
nested if statementsIt allows you to use a single if or else if statement inside of another if or else if statement.

Summary

In summary, you have read about Python Decision Making. We also discussed in this article what is decision-making, single statement suites, and types of decision-making statements.

I hope this article about Decision Making in Python could help you a lot to continue pursuing learning this powerful programming language.

If you want to learn more check out my previous and latest articles for more career-changing articles.

Leave a Comment